I've build an online form, and just need to email it, although I am receiving nothing. Any ideas for getting it working? $message = "Hello"; $headers = "From: Direct Debit Form <info@website.com>\r\n"; $headers .= "Reply-To: info@poshpads.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html"; $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2']; $to = "Direct Debit<dd@website.com>"; mail($to, $subject, $message, $headers); $message = "<div>Your Direct Debit Details have successfully been sent, please print a copy for your own records:</div>"; PHP: Thank you!
I think $to needs to be defined as just an address? $to = "info@website.com"; $from = "dd@website.com"; $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2']; $message = "<div>Your Direct Debit Details have successfully been sent, please print a copy for your own records:</div>"; $headers = "From: Direct Debit Form :" . $from; $headers .= "Reply-To: info@poshpads.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html"; mail($to,$subject,$message,$headers); Code (markup):
The $to can be anything that complies with the http://www.faqs.org/rfcs/rfc2822.html rules. Chances are you are on windows (in which case you don't have sendmail installed). This usually works out of the box on Linux systems.
I have made the changes, code is now: $message = 'Hello'; $headers = "From: info@yourserver.com\r\n"; $headers .= "Reply-To: info@yourserver.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html"; $subject = "Direct Debit form for ".$_POST['account1']." ".$_POST['account2']; $to = "dd@yourserver.com"; mail($to, $subject, $message, $headers); PHP: Originally it was on a windows box, although I have just moved to a linux host and still no success. Thanks for all the help!
Thanks tube ace, I have just tried the code, adjusted, to include valid emails, although nothing is being sent / received. I'll get in touch with the host. Thanks
Have you checked that the mail function is enabled on your host? Add this to a script and see if it's in the information. echo phpinfo(); PHP: Another thing is make sure that error reporting is on full to let you know if there's any problems. Place this code above the script. error_reporting(E_ALL); ini_set("display_errors", 1); PHP:
Is sendmail (or other mail transfer program, such as exim, postfix) set up correctly on the server? Try this first: <?php $result = mail("you@domain.com", "test subject", "test message"); if ($result) echo "Email OK"; else echo "ERROR"; ?> Code (markup): If the above code says ERROR, you may have non working email server. You can also try phpmailer which is capable to send HTML emails, and use mail(), sendmail directly and SMTP (local or external). http://phpmailer.worxware.com/