user4171336
user4171336

Reputation:

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 [email protected]:

$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("[email protected]", $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=<[email protected]>, relay=www-data@localhost
Oct 24 16:41:17 CA2EXAMPLE01 sm-mta[4477]: s9OGfHeD004477: from=<[email protected]>, size=431, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Oct 24 16:41:17 CA2EXAMPLE01 sendmail[4476]: s9OGfHVe004476: [email protected], 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=<[email protected]>, ctladdr=<[email protected]> (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.

Upvotes: 0

Views: 806

Answers (2)

meda
meda

Reputation: 45500

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

Upvotes: 0

Hayk Aramyan
Hayk Aramyan

Reputation: 323

you need to change config of postfix

vim /etc/postfix/main.cf

and remove your domain name from mydestination's value

Upvotes: 1

Related Questions