Page 1 of 1

Mailto position

Posted: Fri Jan 01, 2010 4:13 pm
by wright67uk
I am new to Php and I am struggling with the code below.
I am not recieving an email when I test my form.
Have I put the mailto in the wrong place?
Any help at all would be very much appreciated. - Thanks in advance.

<?php
$mailto = "myemailaddress@hotmail.co.uk" ;
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($name == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

elseif (mail($name,$email,$mailto)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>

Thankyou.

Re: Mailto position

Posted: Fri Jan 01, 2010 5:20 pm
by califdon
The problem is the order of the arguments to the mail() function. See http://php.net/manual/en/function.mail.php. The addressee's email address must be the first argument; you have it as the last argument.