Can I use PHP Mail()?

design

#1

I am using the DH PHP Mail script as listed in the wiki, but I am never receiving the messages. The email addresses are correct and the script is very basic, I haven’t added anything to it. What could the problem be? The page appears to run fine but the email never shows up.

<?php $to = "chad@xxx.com"; $subject = "Website Inquiry"; // compose headers $headers = "From: chad@xxx.com\r\n"; $headers .= "Reply-To: chad@xxx.com\r\n"; $headers .= "X-Mailer: PHP/".phpversion(); // compose message $message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; $message .= " Nam iaculis pede ac quam. Etiam placerat suscipit nulla."; $message .= " Maecenas id mauris eget tortor facilisis egestas."; $message .= " Praesent ac augue sed enim aliquam auctor. Ut dignissim ultricies est."; $message .= " Pellentesque convallis tempor tortor. Nullam nec purus."; $message = wordwrap($message, 70); // send email mail($to, $subject, $message, $headers); ?>

Any ideas?


#2

Hmmm. OK they all just came through…hours later. Guess that answers the question.


#3

You should probably add \r\n\r\n after the last header to help avoid header-injection, check content-type, check all user input, etc…

I’d read through the tips at http://us2.php.net/function.mail for more info.


:stuck_out_tongue: Save up to $96 at Dreamhost with 96DOLLARSOFF promo code (I get $1).
Or save $97 with TAKESEILERSCASH.


#4

I’ve altered the wiki article to reflect this advice - thank you.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#5

It probably wouldn’t hurt to have it suggest this in the headers, unless there’s a reason to change it:

$headers .= “Content-type: text/plain\r\n”;

It’s also not a bad idea to scan all user input for characters you don’t want like: \r, \n, content-type, etc…

Helpful links at PHP.net: mail(), strstr(), stristr(), ereg() and eregi()


:stuck_out_tongue: Save up to $96 at Dreamhost with 96DOLLARSOFF promo code (I get $1).
Or save $97 with TAKESEILERSCASH.


#6

I think it might be better to keep the examples in their simple form, and then add a section on security. Please feel free to update the article as you see fit.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]