Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
771 views
in Technique[技术] by (71.8m points)

email - php mail function

<?php
$sendto = "account@gmail.com";
$subject = "email confirmation"; // Subject 
$message = "the body of the email - this email is to confirm etc...";
# send the email 
mail($sendto, $subject, $message);
?>

this is the code that i wrote to test mail function on localhost. i have ran the script in browser for several times and still dun receive any email in my mail box.

Do I need any additional configurations?

thx in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Basically is hard to send a mail from localhost to any mail providers. They have big restrictions on the incoming mails, and the simply mail() won't work.

You need to use an SMTP server. and define that server in php configuration

smtp = localhost  #(here should be your smtp server)
smtp_port = 25

if you don't have an SMTP server, try to pass all headers like in PHP examples:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "
" .
    'Reply-To: webmaster@example.com' . "
" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

http://www.php.net/manual/en/function.mail.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...