简体   繁体   中英

php mail doesnt work

My host is using SquirrelMail, from the Squirrel panel I can send mail, besides I can receive the mail too. Took simple code to test:

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

if(mail($to, $subject, $message, $headers)){
    echo '1';
}else echo '2';

phpinfo()

SMTP localhost
smtp_port 25
sendmail_from no value    |    no value 
sendmail_path /usr/sbin/sendmail -t -i -f **MAIL**  |   /usr/sbin/sendmail -t -i

where **MAIL** is my personal mail, not the one, I want to send from

But with my script I cant send email. Receive 2. wtf ?

I'm making the assumption that, $to was a valid address when you tested it. Your test code is fine, I just ran it on my host and received an email in my Gmail account.

My assumption then would be that your host hasn't configured email via sendmail. SquirrelMail probably uses SMTP instead, if you have a quick Google there are several SMTP classes out there already that you can use.

Do a quick phpinfo() and look for something like

sendmail_path   /usr/bin/sendmail -t -i /usr/bin/sendmail -t -i

This will tell you if it is at least configured for PHP's use, if it is there and still doesn't work you could try invoking it from the command line directly. If that still doesn't work its probably time to contact your host directly.

I found my admin profile on hosting was not the one I want to send from. Question closed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM