简体   繁体   中英

Can't send email to my own domain

I've set up sendmail on my ubuntu server and I have the following PHP code set up to email my own domain contact@example.com :

$subject = "Hello!";
$message = "This is a test.";

$header = "From: " . $email . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail("contact@example.com", $subject, $message, $header);

However, the email never arrives. However, when I change the destination email to Gmail or Yahoo, the email sends just fine.

This is the output of my mail.log file:

Oct 24 16:41:17 CA2EXAMPLE01 sendmail[4476]: s9OGfHVe004476: from=www-data, size=186, class=0, nrcpts=1, msgid=<201410241641.s9OGfHVe004476@CA2EXAMPLE01.example.com>, relay=www-data@localhost
Oct 24 16:41:17 CA2EXAMPLE01 sm-mta[4477]: s9OGfHeD004477: from=<www-data@CA2EXAMPLE01.example.com>, size=431, class=0, nrcpts=1, msgid=<201410241641.s9OGfHVe004476@CA2EXAMPLE01.example.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Oct 24 16:41:17 CA2EXAMPLE01 sendmail[4476]: s9OGfHVe004476: to=contact@example.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30186, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s9OGfHeD004477 Message accepted for delivery)
Oct 24 16:41:17 CA2EXAMPLE01 sm-mta[4479]: s9OGfHeD004477: to=<contact@example.com>, ctladdr=<www-data@CA2EXAMPLE01.example.com> (33/33), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120431, relay=mail.example.com. [11.23.41.55], dsn=4.0.0, stat=Deferred: Connection refused by mail.example.com.

The main issue I see in the error log is Deferred: Connection refused by mail.example.com , but I'm not sure what's wrong.

you need to change config of postfix

vim /etc/postfix/main.cf

and remove your domain name from mydestination 's value

You need to add an entry for the loopback ip:

#add this to bind hostname
127.0.0.1      CA2EXAMPLE01.example.com//whatever you meant by mail.example.com

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