Solved

Invalid E-mail Address in PHPMailer

Posted on 2013-01-18
6
6,198 Views
Last Modified: 2013-11-13
I'm getting an invalid address error while running the PHP script below. The SMTP credentials and recipient e-mail were altered for this post. They are all valid on the actual script. I don't know why the recipient e-mail is being rejected. I'm trying to send an e-mail with SMTP authentication, and SMTP security (SSL, TLS) is not required.

Any help would be appreciated.

  include 'PHPMailer_5.2.2/class.phpmailer.php';
  
  function SendConfirmation ($sName, $sEmail)
  {
    $mail = new PHPMailer ();
    
    $mail->SMTPDebug  = 2;
    
    $mail->Host = "mail.exchange.telus.com";
    $mail->IsSMTP ();
    $mail->Username = "inbin@website.com";
    $mail->Password = "password";

    $mail->From = "inbin@website.com";
    $mail->FromName = "Web Site";

    $mail->AddAddress ($sEmail, $sName);

    $mail->Subject = 'PHPMailer Test' . date ('Y-m-d H:i:s');
    $mail->Body = "This is a test.";

    if ($mail->Send ())
      echo "\r\nMail sent.";
    else
      echo "\r\nMail not sent. " .  $mail->ErrorInfo;
    
    echo "\r\n";
  }  
  
  /***[ Main ] **************************************************************************/
  
  $sName = 'Johan Cyprich';
  $sEmail = 'jcyprich@website.com';
  
  $bSent = SendConfirmation ($sName, $sEmail);

Open in new window

0
Comment
Question by:BetaPictoris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38795042
Are you getting the error from PHPMailer or returned from the SMTP Server?  And does it work for you with other email addresses?
0
 

Author Comment

by:BetaPictoris
ID: 38795078
The error is coming from PHPMailer. I use the same SMTP settings for other web sites on the same server, include Joomla 2.5 which uses its own PHPMailer internally. There is probably some switch I need to turn on in the script to make it send.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38795110
I haven't seen any switch that was needed in PHPMailer in order to send email.  Can you send an email to yourself by changing just the recipient email address?  And can you post the exact error message so I can look it up in the PHPMailer code?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:BetaPictoris
ID: 38795261
This is the error I get:

---
Invalid address: jcyprich@website.com
You must provide at least one recipient email address.
---

The mail server does not require SMTP security (i.e. no SSL or TLS). I use the same settings with other PHP apps on the same server with success.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38795368
I just used your code above by substituting my own email addresses and server info and it works fine.  The error message is generated by a statement that counts the number of email addresses in the 'to', 'cc', and 'bcc' inputs and when it does not find one, it outputs that error message.  

The 'AddAddress' function calls 'ValidateAddress' in a second step.  That consists of a very long regex to compare the address against.  If you have an unusual email address, it is possible that it will fail that comparison.  It turns out in research on 'validating email addresses with regex' that is also impossible to create a 'regex' that account for all possible variatons.

The "charset" is defined as 'iso-8859-1'.  If your characters in the address are not in that character set, it may also be a problem.
0
 

Author Comment

by:BetaPictoris
ID: 38801902
Thanks for the info. I tried modifying the AddAnAddress function in PHPMailer but still had the same problem. The e-mails that I'm using are valid e-mails and they work with every other web application.

My solution is to not use PHPMailer and instead use another open source PHP library that I found. I would use PHPMailer again if the bugs were fixed.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Block spoofing emails 3 42
Code not executing correctly. 3 44
Change Exchange sync schedule on Samsung Galaxy S8 1 65
Transactional email SMTP relay 5 12
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question