php mail function

by 15 replies
18
My php mail function is only working for gmail...please tell me if you found any error...i need to send email in Hotmail and yahoo as well.

$cemail = trim($_POST['cemail']);
$cname = trim($_POST['cname']);
$subject = "Contact Us";
$message .= "<table><tr><td>Name : </td><td>$cname</td></tr> <tr><td>Email : </td><td>$cemail</td></tr></table>";

$message .= trim($_POST['cmsg']);
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: $cname<$cemail>" . "\r\n";
$headers .= "X-Mailer: PHP's mail() Function\n";
$to = "abc@hotmail.com";

if(mail($to,$subject,$message,$headers)){
$msgsent = "Thanks for contacting Us";
}
#programming #function #mail #php
  • They might be marking it as spam,and your mail not getting through at all to hotmail and the like.

    if the mail is being sent, there is nothing wrong with your script. maybe look at using smtp to send the mail through instead of the php mail() function. And send only plain text messages.
    • [1] reply
    • If the script is sending mail, then the script is working fine, its likely hotmail/yahoo is filtering it or sometimes I found yahoo delivers the email very very late.

      To improve this issue you can check if your Domain's Reverse DNS and MX records set correctly, you can ask your server admin for assistance in this matter.
      • [1] reply
  • Talk to your host. Some of them block outgoing email on shared hosting/vps's.
  • I propose stripping off the html headers first, trying simple text. If simple text works, then you'll know where the issue is
    • [ 1 ] Thanks
    • [1] reply
    • Correct answer.

      Code should always be stripped down when facing issues, even if it works sometimes. The HTML you're sending is not proper e-mail HTML, and, combined with your headers, it may be causing issues.

      Of course, it may just be you're e-mails are being blocked, but you need to try basic text e-mails first to see if this is the issue.
  • Banned
    [DELETED]
  • Maybe your host blocked function mail() to yahoo, you can send mail with method SMTP. Here is a lirbrary smtp use to send mail in php, you can use it to send email on your site.
  • I would suggest to use an SMTP, there are several ones like : Sendgrid, Mandrill, SendinBluem they are free and their reputation is much higher than your local/shared ip.
  • If you can, look at the mail log to look for errors - like the others say, rdns etc needs to be spot on to get to Yahoo et all.

    First thing I normally do is log into my VPS (not sure of your set up), and watch the mail queue whilst filling out the form. If you see the mail leaving the server you can then look at the logs etc to see if there are any messages from the far end.
  • Shoot me a private message I'm happy to help out.
  • It might be a good idea to set up spf record also. Basically it tells which mail server can send emails on behalf of your domain.
  • see if your emails are landing into spam/junk folder. you must add spf for gmail and yahoo. a good practice is to add spf and dkim to send emails. if you don't know about spf and dkim ask your host to add it for you.
  • Code:
    X-Mailer: PHP's mail() Function
    Blocked by at least hotmail :rolleyes:
  • Yes, I also agree with shahriyar.
    • [1] reply
    • With mail()? You don't. It blindly shoots the mail out and doesn't handle a lot of possible failure modes. Even then, there's no effective way to capture error output and take appropriate actions.
      Use a mail library that either speaks to your local SMTP server or can invoke sendmail and understand the output enough to verify that the message was accepted for relay. SMTP is vastly preferred here because it's way more verbose when the local relay won't accept the message.

Next Topics on Trending Feed

  • 18

    My php mail function is only working for gmail...please tell me if you found any error...i need to send email in Hotmail and yahoo as well. $cemail = trim($_POST['cemail']);