We recently upgraded our webserver and one of the first issues we came across was having problems sending to the same domain because the website was hosted on a different server to the company’s exchange server. Anyway I fixed that it was some simple config changes and disabling the mail service for the domain.
Anyway, that’s not working but what I didn’t notice at the time when I was testing some PHP mail forms on the website was that they are all getting sent as my email address to the client.
This is the PHP (Which I don’t think is a problem)
<?php
ini_set("sendmail_from", "noreply@******.com");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$ip=$_SERVER['REMOTE_ADDR'];
$recipient = '*****@******.com';
$subject = "Comments submitted from the Contact Us form on www.wavesfm.com from $name" ;
$message = "This is an email submitted from the Contact Us form on the website www.*****.com containing details from $name n";
$message .= " n";
$message .= "Name: $name n";
$message .= "Email: $email n";
$message .= "Phone Number: $phone n";
$message .= "Comments: $comments nnn";
$message .= "IP Address: $ip ";
$headers = "From: noreply@********.com n";
$headers .= "Reply-To: $email";
mail($recipient,$subject,$message,$headers);
header( 'Location: http://www.*****.com/thanks.php' ) ;
?>
Can anyone see any issues with that code? I have tried adding -fnoreply@**.com as a send parameter but it wont change my own email address from appearing as the sender.
I don’t think this is a PHP issue it seems more like a Postfix issue, but whats really bothering me is how my email address which isn’t used anywhere is appearing as the sender.
Has anyone had experience with this before? as before 2 weeks ago I hadn’t used Postfix at all so its all rather new to me.
Web Server: Cent OS, Plesk 11.0.9
Mail Server: MS Exchange Mail Server / Using ORF
Postfix Log for one of the email’s
Mar 27 13:48:41 dedicated postfix/pickup[12199]: 652EFA106C5: uid=48 from=
Mar 27 13:48:41 dedicated postfix/cleanup[14376]: 652EFA106C5: message-id=<[email protected]>
Mar 27 13:48:41 dedicated postfix/qmgr[12198]: 652EFA106C5: from=, size=726, nrcpt=1 (queue active)
Mar 27 13:48:41 dedicated postfix/smtp[14378]: certificate verification failed for mail.mydomain.com[82.888.888.51]:25: untrusted issuer /CN=clientdomain-WAV01-CA
Mar 27 13:48:42 dedicated postfix/smtp[14378]: 652EFA106C5: to=, relay=mail.client_website.com[82.888.888.51]:25, delay=0.89, delays=0.04/0.01/0.36/0.48, dsn=2.6.0, status=sent (250 2.6.0 <[email protected]> [InternalId=11846] Queued mail for delivery)
Mar 27 13:48:42 dedicated postfix/qmgr[12198]: 652EFA106C5: removed
2
Answers
There might be some string concatenation issues with the following code:
try
I recommend using phpmailer class for sending emails which is widely used:
https://github.com/Synchro/PHPMailer
The php.ini sendmail_from directive only really applies on windows boxes
I don’t think it’s a code issue as such. Which user are you running the webserver+php environment from on your Linux box? If you’re running it as yourself then it’s probably submitting to postfix using your email address.
Don’t forget to tail /var/log/maillog if you’re using postfix, that can tell you a lot and help you get to the bottom of the issue.
sudo tail -f /var/log/maillog
You could try signing up for a free account with Sendgrid and coupled with PHPMailer, Zend Mailer or Symfony Mailer libraries use that to send the emails and see if you get the same issue.