Solved

Invalid E-mail Address in PHPMailer

Posted on 2013-01-18
6
5,508 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now