/    Sign up×
Community /Pin to ProfileBookmark

Problem with mailform

I have read previous topics but can’t find anything to help me telling wat’s wrong in my code.
It tells me all the time that the email is incorrect.

[code=php]<div id=”valkommen”>
<h2 class=”cleartopmargin”>Kontakta oss </h2>
<br />
<br />

<?php

function valid_email($email) {
$pattern = “/^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-w]*[0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/”;
if (preg_match($pattern, $email)) {
return true;
}
else {
return false;
}
}

if (isset($_POST[‘sendemail’]) && !empty($_POST[‘name’]) && !empty($_POST[‘subject’]) && !empty($_POST[’email’]) && !empty($_POST[‘msg’])) {
if (!valid_email($email)) { echo “<p class=”red”>You typed an unvalid email adress<br /><br /></p>”; }
else {
$to = “[email protected]”;
$subject = “Från Testzoneformuläret: ” . $_POST[‘subject’];
$msg = “Skickat från formuläret”.”rnrn”.”Från: “.$_POST[‘name’].”rn”.”E-post: “.$_POST[’email’].”rnrn”.”Meddelande: “.”rn”.$_POST[‘msg’];
$headers = “From: [email protected]”;

mail($to, $subject, $msg, $headers);
echo “thx!”;
}}
elseif (isset($_POST[‘sendemail’])) {
echo “<p class=”red”>You forgot to type in all fields!</p>”;

}
?>

<form action=”index.php?p=contact” method=”POST”>
Namn<br />

<input name=”name” type=”text” class=”input” size=”25″ />
<br />
E-postadress<br />
<input name=”email” type=”text” class=”input” size=”25″ />
<br />
&Auml;rende<br />
<select name=”subject” size=”1″>
<option value=”Information”>Information</option>
<option value=”Annonsering”>Annonsering</option>
<option value=”Forum”>Forum</option>
<option value=”Tester”>Tester</option>
<option value=”Support”>Support</option>
<option value=”&Ouml;vrigt”>&Ouml;vrigt</option>
</select>
<br />
<br />
Meddelande<br />
<textarea name=”msg” rows=”10″ cols=”35″ class=”textfield”></textarea>
<br />
<br />
<input type=”submit” value=”Skicka” name=”sendemail” class=”buttons” />
</form>
</div>

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@alxlaauthorJan 03.2007 — Changed the code a bit now but I get an error msg instead:

Parse error: syntax error, unexpected T_FUNCTION
[Code]
...$email_adress = $_POST['email']
function is_valid_email($email_address) {
$pattern = "/^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-w]*[0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/";
if (preg_match($pattern, $email_address)) {
return true;
}
else {
return false;
}
}


if (isset($_POST['sendemail']) && !empty($_POST['name']) && !empty($_POST['subject']) && !empty($email_adress) && !empty($_POST['msg'])) {
if (!is_valid_email($email_adress)) { echo "<p class="red">Du skrev in en ogiltig email adress<br /><br /></p>"; }
else { ...
[/Code]
Copy linkTweet thisAlerts:
@blulagoonJan 03.2007 — ...$email_adress = $_POST['email']

This should end with a ; that might be error

Blu
×

Success!

Help @alxla spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...