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);
Make sure you have valid email addresses for AddReplyTo and/or AddAddress.
I had the same problem and it turned out to be because I was setting empty values for AddReplyTo.
Related
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$message = $_POST["message"];
$mailbody="";
$mailbody.="Hello,<br/><br/>You have a new contact on your website:<br/><br/>";
$mailbody.="Name: ".$name."<br />\r\n";
$mailbody.="Email: ".$email."<br />\r\n";
$mailbody.="Phone: ".$phone."<br />\r\n";
$mailbody.="Message: ".$message."<br />\r\n";
require_once('./bat/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
// SMTP Configuration
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.office365.com"; // SMTP server
$mail->Username = "email#domain.com";
$mail->Password = "****";
$mail->Port = 587; // optional if you don't want to use the default
$mail->IsHTML(true);
$mail->From = "email#domain.com";
$mail->FromName = "Website Name";
$mail->Subject = "Subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($mailbody);
// Add as many as you want
$mail->AddAddress("email#domain.com", "Name");
if(!$mail->Send()) {
//header("Location:contact.php?sent=0#sent");
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header("Location:contact.php?sent=1#sent");
}
When I test on localhost the email sends successfully and gets delivered.
When I test online it throws the following error: Mailer Error: SMTP connect() failed.
I tried to remove $mail->IsSMTP(); as mentioned in one of the suggestions. The scripts runs online and returns true but the email never gets delivered.
i'm trying to send a mail using stmp configuration but it always displays a puny encode invalid error . I'm guessing it's my validation method that has a bug when the prce8 is selected ( i'm using php5 so it selects as best choice pcre8). I have already checked on that answer but still does not work !
<?php
require_once('class.mail.php');
$to=isset($_POST['verify'])?$_POST['verify']:false;
$subject="TSHED Email verification";
$message='<html><p> my message </p></html>';
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
// SMTP Configuration
$mail->SMTPsecure='ssl';
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.gmail.com "; // SMTP server
$mail->Username = "myEmail";
$mail->Password = "mypassword";
$mail->Port = 465; // optional if you don't want to use the default
$mail->From = "<FromanEmail>";
$mail->FromName = "Name";
$mail->Subject = $subject;
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->isHTML($message);
$mail->Body=$message;
$mail->msgHTML($message);
// Add as many as you want
$mail->AddAddress($to,'USER');
if(!$mail->Send())
{ //echo"endterer";
$response = "Message error!".$mail->ErrorInfo;
echo $response;
echo $to;
}
else {
$response = "Message sent!";
echo $response;
}
?>
Any Help Please ?
my pcre8:
case 'pcre8':
return (boolean)preg_match(
'/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}#)' .
'((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
'(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
'([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
'(?2)")(?>(?1)\.(?1)(?4))*(?1)#(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
'(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
'|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
'|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
$address
);
exemple of valid Email: ouedson0128#yahoo.fr
Error :Invalid address: (punyEncode)
Seems it is a bug in phpMailer. Try another version
Instead of using php's mail() function, I've been trying to set up PHPMailer with no success. I put in "echo here" for debugging purposes, and that is all it shows. I do not get any emails, or the sent or error messages. I'm stumped, and after researching it on here may switch to swift mailer. I'd really like to know what I screwed up though.
In my code, address is set to my email, and the username and password are set to a dummy account I made.
<?php
include('class.phpmailer.php');
$mail = new PHPMailer();
$address = "test#gmail.com";
$body = "test email";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$mail->SetFrom('name#yourdomain.com', 'Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);
echo "Here";
if($mail->Send()) {
echo "Message sent!";
}
else {
echo "Mailer Error: " ; $mail->ErrorInfo;
}
?>
As you are using Gmail I think you must make sure the gmail account has the insecure application auth activated
I want to send email to users who click on forgot password link on my website from no-reply#mycompanmysname.com.
I am able to send mail through my companys mail server but I do not want my companys email address to be displayed.
Can anybody suggest how is that done?
I am using phpmailer and this is my code:
$from = "companyname#yahoo.com";
$mail = new PHPMailer();
$body = $messageBody;
$mail->SMTPSecure = 'tls'; //added
$mail->SMTPAuth = true;
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->Host = "smtp server name";
$mail->Port = 587;
$mail->Username = "********";
$mail->Password = "******";
$mail->From("$name");
//$mail->SetFrom("$from");
$mail->MsgHTML($body);
$mail->AddAddress("$toEmail");
$mail->Subject = "".$subject."";$mail->Body = $headers . "<br>" . $messageBody . "<br>" . $confidential;
$mail->WordWrap = 50;
$mail->MsgHTML($mail->Body);
if(!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
print "<p class='Error'>Error in sending email.Please try again.</p>";
} else {
print "<p class='success'>An email is sent to you with the access information.</p>";
}
Taking an example from their docs, you can do something like this:
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
From personal experience, you can do this and it works, but in some mail clients, such as Gmail, you'll get something along the lines of From: email#website.com via otherdomain.com. I'm not sure if there's a way outside of this other than adding some DNS settings. Not sure if you have access to that.
I'm php newbie that just figured out how to use php with phpmailer to send email addresses of my users to my email address to be added to a newsletter.
However, now I want to add a simple auto-respond script in php, so when users add their email to my guestlist it sends them an autoreply email to their email that says:
Thanks for signing up. [Picture of my logo] www.mysite.com
I've searched and searched, but I haven't been able to find a proper answer on how to create an autorespond script in php. Please let me know how I can accomplish this task. Thank you!
<?php
$email = $_REQUEST['email'] ;
require("C:/inetpub/mysite.com/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
$mail->Host = "smtp.comcast.net"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myusername#comcast.net"; // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;
$mail->From = $email;
// below we want to set the email address we will be sending our email to.
$mail->AddAddress("myemail#gmail.com", "Guestlist");
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "A new member wishes to be added";
$message = $_REQUEST['message'] ;
$mail->Body = $email;
$mail->AltBody = $email;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
$mail2 = new PHPMailer();
// set mailer to use SMTP
$mail2->IsSMTP();
$mail2->Host = "smtp.comcast.net"; // specify main and backup server
$mail2->SMTPAuth = true; // turn on SMTP authentication
$mail2->Username = "myusername#comcast.net"; // SMTP username
$mail2->Password = "*******"; // SMTP password
$mail2->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail2->Port = 25;
$mail2->From = $email;
// below we want to set the email address we will be sending our email to.
$mail2->AddAddress("$email");
// set word wrap to 50 characters
$mail2->WordWrap = 50;
// set email format to HTML
$mail2->IsHTML(true);
$mail2->Subject = "Thank you for joining";
$message = "Please stay tune for updates" ;
$message = $_REQUEST['message'] ;
$mail2->Body = $message;
$mail2->AltBody = $message;
if(!$mail2->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail2->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
Update: 1
Ok, I figured out how to send auto-respond emails to users. However, now the users are receiving messages with their own email address and the name Root user
So what can I do to fix this problem so that users see my email address when they recevie auto-responses, and how can I make sure it says my name instead of root user?
Do not use the submitter's email address as the from address - it won't work as it looks like a forgery and will fail SPF checks. Put your own address as the From address, and add the submitter's address as a reply-to.
Using SMTPSecure = 'ssl' with Port = 25 is an extremely unusual combination, and very likely to be wrong. ssl/465 and tls/587 are more usual.
To send multiple messages, you do not need to create a second instance - just re-use the same one. You can reset any individual properties you want (such as Body) and clear addresses using $mail->clearAddresses(), then just call $mail->send() a second time.
It looks like you have based your code on an old example (try a new one) - make sure you are using latest PHPMailer - at least 5.2.10.
add:
echo "Message has been sent";
$mail = new PHPMailer();
$mail->From = 'myemail#gmail.com';
// below we want to set the email address we will be sending our email to.
$mail->AddAddress($email);
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "Thanks for joining ...";
$message = "Thanks for joining...";
$mail->Body = $email;
$mail->AltBody = $email;
$mail->Send();