Jump to content

PHP mail and SMTP


drmota

Recommended Posts

Hello,

 

Something that's been really bugging me the last days is a problem in PHP, the mail(); function, so here goes.

 

First, my script:

 

$to = "valid@hotmail.com";
$subject ="contact form";
$body = "Hello, you have been contacted";
$from = "$_POST['email'];
$headers = 'From : valid@hotmail.com'."\r\n".'Reply-To: valid@hotmail.com';
if (mail($to, $subject, $body, $headers)) {
echo "worked";
} else {
echo "didn't work";
}

 

I'm using Ubuntu linux and have set up an SMTP server like so:

 

sudo apt-get install postfix

 

And configured it.

 

I have also forwarded TCP port 25 to the server.

 

Problem: I run the script and it echos 'worked', meaning that there was no error. However, I don't get a mail sent into my inbox.  :wtf: :'(

 

Thanks in advance,

Drmota

Link to comment
Share on other sites

mail() should use SMTP sockets.

 

You need to check your SMTP server's logs to verify whether the mail was actually sent or not. Assuming you have PHP sey up properly to use your server when you call the mail() function, any debugging beyond that is through your mail server.

Link to comment
Share on other sites

This is what it says about the postfix I set-up:

 

(It says this like 200 times):

 

Aug 18 17:43:58 Vojta2 postfix/smtpd[3735]: lost connection after RCPT from 114-42-140-172.dynamic.hinet.net[114.42.140.172]
Aug 18 17:43:58 Vojta2 postfix/smtpd[3735]: disconnect from 114-42-140-172.dynamic.hinet.net[114.42.140.172]
Aug 18 17:47:18 Vojta2 postfix/anvil[3739]: statistics: max connection rate 1/60s for (smtp:114.42.140.172) at Aug 18 17:43:56
Aug 18 17:47:18 Vojta2 postfix/anvil[3739]: statistics: max connection count 1 for (smtp:114.42.140.172) at Aug 18 17:43:56
Aug 18 17:47:18 Vojta2 postfix/anvil[3739]: statistics: max cache size 1 at Aug 18 17:43:56
Aug 18 18:09:01 Vojta2 CRON[3751]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete)
Aug 18 18:11:52 Vojta2 postfix/qmgr[1813]: 9F95876042C: from=<nobody@Vojta2>, size=402, nrcpt=1 (queue active)
Aug 18 18:11:52 Vojta2 postfix/qmgr[1813]: 3C2DC760425: from=<nobody@Vojta2>, size=373, nrcpt=1 (queue active)
Aug 18 18:11:52 Vojta2 postfix/qmgr[1813]: 4E0B1760427: from=<nobody@Vojta2>, size=402, nrcpt=1 (queue active)
Aug 18 18:11:52 Vojta2 postfix/smtp[3762]: connect to mx3.hotmail.com[65.54.188.126]:25: No route to host
Aug 18 18:12:22 Vojta2 postfix/smtp[3760]: connect to mx3.hotmail.com[65.55.92.184]:25: Connection timed out
Aug 18 18:12:22 Vojta2 postfix/smtp[3761]: connect to mx4.hotmail.com[65.55.92.136]:25: Connection timed out
Aug 18 18:12:22 Vojta2 postfix/smtp[3762]: connect to mx1.hotmail.com[65.55.92.168]:25: Connection timed out
Aug 18 18:12:25 Vojta2 postfix/smtp[3761]: connect to mx3.hotmail.com[65.55.37.88]:25: No route to host
Aug 18 18:12:52 Vojta2 postfix/smtp[3760]: connect to mx2.hotmail.com[65.55.37.120]:25: Connection timed out
Aug 18 18:12:52 Vojta2 postfix/smtp[3762]: connect to mx1.hotmail.com[65.55.37.104]:25: Connection timed out
Aug 18 18:12:55 Vojta2 postfix/smtp[3761]: connect to mx1.hotmail.com[65.54.188.126]:25: Connection timed out
Aug 18 18:13:22 Vojta2 postfix/smtp[3760]: connect to mx1.hotmail.com[65.55.92.184]:25: Connection timed out
Aug 18 18:13:22 Vojta2 postfix/smtp[3762]: connect to mx4.hotmail.com[65.55.92.136]:25: Connection timed out
Aug 18 18:13:25 Vojta2 postfix/smtp[3761]: connect to mx1.hotmail.com[65.54.188.72]:25: Connection timed out
Aug 18 18:13:52 Vojta2 postfix/smtp[3760]: connect to mx2.hotmail.com[65.55.92.152]:25: Connection timed out
Aug 18 18:13:52 Vojta2 postfix/smtp[3762]: connect to mx1.hotmail.co

 

And then this:

 

Aug 18 13:34:21 Vojta2 postfix/smtp[3102]: 4E0B1760427: to=<misc.drmota@hotmail.com>, relay=none, delay=75992, delays=75842/0.05/150/0, dsn=4.4.1, status=deferred (connect to mx4.hotmail.com[65.55.37.88]:25: Connection timed out)

 

Any ideas?

Link to comment
Share on other sites

You have to have a static IP in order to send mail to providers like hotmail yahoo etc

If its not static then yahoo or whoever will think its spam and block it from coming through. Although.. it does go through sometimes, usually takes about 4-5 hours though and it ends up in the spam folder.

 

Having the same problem.. and I can't get a static IP. My fix was to host it somewhere else using vps.

Link to comment
Share on other sites

You have to have a static IP in order to send mail to providers like hotmail yahoo etc

If its not static then yahoo or whoever will think its spam and block it from coming through. Although.. it does go through sometimes, usually takes about 4-5 hours though and it ends up in the spam folder.

 

Having the same problem.. and I can't get a static IP. My fix was to host it somewhere else using vps.

 

Another issue is that your pretending to send the mail from a hotmail address. The client will see that the actual server and the From address differ and mark the emails as spam. You should always send your emails from a valid email address on the actual server sending the email.

Link to comment
Share on other sites

You have to have a static IP in order to send mail to providers like hotmail yahoo etc

If its not static then yahoo or whoever will think its spam and block it from coming through. Although.. it does go through sometimes, usually takes about 4-5 hours though and it ends up in the spam folder.

 

Having the same problem.. and I can't get a static IP. My fix was to host it somewhere else using vps.

 

Another issue is that your pretending to send the mail from a hotmail address. The client will see that the actual server and the From address differ and mark the emails as spam. You should always send your emails from a valid email address on the actual server sending the email.

 

My ISP is giving me a dynamic IP, which is static. This may be a problem then ;s

 

Will setting up an Evolution E-mail (im using Ubunty) and using that one to send help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.