Why won't PHP Mail send emails to hyphenated email addresses (e.g. digital-ocean@hotmail.com)

June 1, 2015 4k views
Email PHP Ubuntu

It works fine with email addresses without hyphens (e.g. digitalocean@hotmail.com). Does anyone know a possible cause for this?

Please ask if you need any more information.

  • Can you share a sample of the code attempting to send the messages?

    I have never encountered this myself when sending emails via php but some googling found a number of people reporting similar issues and the primary suggestions I found there were:

    • Escape the hyphen: digital\-ocean@example.org
    • Wrap the email in quotes: "digital-ocean@example.org"
    • use angle brackets: <digital-ocean@example.org>
  • Here is the script. As you can see I'm using PHP Mailer

    require 'PHPMailer.php';
    $name = $_POST['name'];
    $email = $_POST['email'];
    $tel = $_POST['tel'];
    $where = $_POST['where'];
    $message = $_POST['message'];
    $to = "";
    if ($where == "one") {
      $to = "email1@example.com";
    } elseif ($where == "two") {
      $to = "email-2@example.com";
    $mail = new PHPMailer;
    $mail->From = 'form@example.com';
    $mail->FromName = 'Website Contact Form';
    $mail->Subject = "Contact Form Submission";
    $mail->Body = "<b>Name:</b> " . $name . "<br><br><b>Email:</b> " . $email . "<br><br><b>Telephone:</b> " . $tel . "<br><br><b>Where They Are:</b> " . $where . "<br><br><b>Message:</b> " . $message; 


  • Looking at PHPMailer's source code, it appears to encode a recipient email address only if there is a name. Try passing a name to addAddress(), does that work?

    $mail->addAddress($to, 'Name here');
  • I tried that and it didn't work. I think it says somewhere that the name isn't required anyway.

  • Now I can't send emails at all. I get this line in my mail.log

    Jun  2 16:33:54 McCarthee sm-mta[22590]: t52KXqS3022588: t52KXsS3022590: DSN: Service unavailable
1 Answer
Have another answer? Share your knowledge.