Jump to content

Archived

This topic is now archived and is closed to further replies.

evilandy

mail() not working properly

Recommended Posts

so, I'm working on a contact form and I finished my code and everything andd it looks fine but it gives me an error on the line with the actual mail() function
[code]<?php
$name=$_POST['name'];
$email=$_POST['senderemail'];
$subject=$_POST['subject'];
$reason=$_POST['reason'];
$message=$_POST['message'];
$message=wordwrap($message, 70);
$ip = getenv('REMOTE_ADDR');

if ($reason == 'nothingselected') {
    echo "You must select a reason for contact to procede. <a href=\"contact.html\">Go Back.</a>";
}
else {
    mail($reason, $subject, 'Sender: '$name'('$email')\n Sender\'s IP: '$ip'\n\nMessage: '$message, 'From: '$name 'Reply-To: '$email);
    echo "Thank you for your message.";
}
?>[/code]
can someone tell me whats wrong with it?

Share this post


Link to post
Share on other sites
You should start with the reciepents email adress, read the manual on how to use the mail function: [a href=\"http://no.php.net/manual/en/function.mail.php\" target=\"_blank\"]http://no.php.net/manual/en/function.mail.php[/a]
[code]
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
[/code]

Share this post


Link to post
Share on other sites
yes, $reason is the recipients email, it would make more sense if I posted the form, but besides that, is there anything wrong?

Share this post


Link to post
Share on other sites
Its a mix with single quotes i imagine, try this:
[code]
$headers = "From: $name \r\n";
$headers .= "Reply-To: $email \r\n";

mail($reason, $subject, "Sender: $name ($email)\r\nSender IP: $ip\r\n\r\nMessage: $message", $headers);
[/code]

And you should consider adding some more headers to avoid spam filters, i also suggest to keep it tidy - putting everything written in between the mail function easily screws thing up.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.