Solved

Invalid E-mail Address in PHPMailer

Posted on 2013-01-18
6
5,274 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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:BetaPictoris
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

772 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

10 Experts available now in Live!

Get 1:1 Help Now