Jump to content

mail() not working properly


evilandy

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?
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.