mail() problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonathant
Forum Commoner
Posts: 32
Joined: Sat Jan 07, 2006 3:13 pm

mail() problems

Post by jonathant »

A client has a website that is remotely hosted on a shared server. He also has an exchange server that listens for mail sent his domain name, which is the same domain name as his website. So, the MX records for the domain name are pointed to his exchange IP address while the DNS records are pointed to the website server IP address. Make sense?

On the website I have a form that customers fill out. I want the results from the form to be sent to the sales guy. I'm just using mail(). The mail never makes it to the exchange server. If I check for the mail on the web host's webmail, I can find it there. If I send the mail to my personal email account (ie, any account that isn't the same domain name as the website) the mail makes it.

Is this a PHP or a DNS problem? Can I trick PHP to send the mail to an IP address rather than the domain name, like user@122.22.22.22?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think you can use Swiftmailer (http://www.swiftmailer.org) to address that issue. I think mail() uses sendmail as a default, which might be causing you problems. Another thing to do is test mail() using a conditional to see if it was accepted my the mail server for delivery.

Code: Select all

<?php
if (mail($to, $subject, $msg))
{
  echo 'It was accepted for delivery';
}
else
{
  echo 'Crapola';
}
?>
Last edited by RobertGonzalez on Sat Mar 03, 2007 9:04 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If you use Swift Mailer then the simplest solution would be to simply send the email straight to the exchange server by IP, using the SMTP connection.
Post Reply