Solved

Invalid E-mail Address in PHPMailer

Posted on 2013-01-18
6
6,514 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 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