Solved

Invalid E-mail Address in PHPMailer

Posted on 2013-01-18
6
5,678 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

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.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

809 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