This is my php code to send a confirmation email to a new user and the problem is, i am not receiving it(i have tried different ones, no luck)
function send_email($info)
{
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Welcome to Site Name');
$message ->setFrom(array('noreply#localhost' => 'localhost'));
$message ->setTo(array($info['email'] => $info['username']));
$message ->setBody($body_plain_txt);
$message ->addPart($body, 'text/html');
$result = $mailer->send($message);
return $result;
}
I get no errors
Install phpmailer.
Here is a sample on how to send mail with PHP mailer
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
If your destination address is #hotmail.com it may never income because they have a strong anti-spam management.
Related
Currentlt it shows the mail on which phpmailer SMTP is registered.
$email='abc#email.com';
$subjectRsc="Any";
$message='Welcome';
phpmail($email, $subjectRsc, $message);
My phpmailer function:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->AddReplyTo(REPLY_EMAIL, 'ABC');
$mail->SetFrom(FROM_EMAIL, 'ABC');
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return true;
}
This is how I am sending mails to the users I want to show the specific mail of my website to be displayed in the mails not that on which smtp server is registered.
You should try this :
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->addReplyTo('myemail#example.com', 'ABC'); //<-- this is the line i changed
$mail->From= "myemail#example.com"; //<-- this is the line i changed
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return true;
}
According to phpmailer documentation this is the field to add the sender's email.
please try using this code :
<?php
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "from#yourdomain.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("test#gmail.com", "Test");
$mail->addAddress("test1#gmail.com");
//Address to which recipient will reply
//if you want to add CC and BCC
$mail->addCC("cc#example.com");
$mail->addBCC("bcc#example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
Please try using this code:
<?php
$to = "test#gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:test1#gmail.com \r\n";
$header .= "Cc:test2#gmail \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
I have a form in my website. When the user fills out the form, I want an email to be sent to me with data entered in the form and also a thank you email for the person filling the form.
This is the code I am using:
<?php
function sendEmail($subject, $body) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl"; // does tls works with port 25
$mail->Host = 'smtp.zoho.com'; // is this the correct
$mail->Port = 465;
$mail->Username = "noreply#domain.org";
$mail->Password = "mypassword";
$mail->SetFrom("noreply#domain.org");
$mail->Subject = $subject;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress('data#domain.org');
if(!$mail->Send()) {
$mail->ErrorInfo;
echo "<script>alert('Error Occured sending the enquiry. Please try again')</script>";
}
else
{
echo "<script>window.location.href='http://domain.com/index.html'</script>";
}
}
?>
<?php
function sendEmail($subject, $body) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 3;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl"; // does tls works with port 25
$mail->Host = 'smtp.zoho.com'; // is this the correct
$mail->Port = 465;
$mail->Username = "noreply#domain.org";
$mail->Password = "mypassword";
$mail->SetFrom("noreply#domain.org");
$mail->Subject = $subject;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress(''.$_POST['emailAddr'].''); // **
emailAddr is the name for email field in the form and I wish to send email to this email address.
$mail->Subject = 'Thank you for contacting Domain';
$mail->Body = 'Thanks for getting in touch. Your message has been received and will be processed as soon as possible.';
if(!$mail->Send()) {
$mail->ErrorInfo;
echo "<script>alert('Error Occured sending the enquiry. Please try again')</script>";
}
else
{
echo "<script>window.location.href='http://domain.com/index.html'</script>";
}
}
?>
I am working on a project and in my registration form when the user registers I want to E-mail them an activation link. the registration form works, but I am having issues with the E-Mail server. This is my php code using Phpmailer that I have but it is not working and I do not know why !
require 'include/class.phpmailer.php';
require 'include/PHPMailerAutoload.php';
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = jalilmotaz;
$mail->Password = *****;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
Any sugesstions on how to work this out by gmail or some other way?
Multiple mistakes in your code.
1). SSL is deprecated. Use tls.
2). Put your full gmail email and password, and within double quoted ".
<?php
require 'include/class.phpmailer.php';
require 'include/PHPMailerAutoload.php';
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = "youremail#gmail.com";
$mail->Password = "passwordhere";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
?>
$msg = 'God Bless You';
$subj = 'Ryan D\'souza Photgraphy Invoice';
$to = $_POST['email'];
$from = 'emailaddres';
$name = $_POST['client'];
smtpmailer($to,$from, $name ,$subj, $msg);
function smtpmailer($to, $from, $from_name = 'Ryan D\'souza Photgraphy', $subject, $body)
{
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.sendgrid.net';
$mail->Port = 465;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->IsHTML(true);
$mail->From="emailaddres";
$mail->FromName="Ryan D'souza Photgraphy";
$mail->Sender=$from; // indicates ReturnPath header
$mail->AddReplyTo($from, $from_name); // indicates ReplyTo headers
$mail->AddCC('cc#site.com.com', 'CC: to site.com');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAttachment('pdfs/'.$_POST['client'].'.pdf');
$mail->AddAddress($to);
$mail->AddAddress("emailaddres");
if(!$mail->Send())
{
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
}
else
{
$error = 'Message sent!';
return true;
}
}
I'm using PHP mailer to attach a file and send mail. the code works on local system but when I upload it on the server that time it gives me Internal server error. I tried commenting and print each line of the code and found out that i get at $mail->Send().
I have used PHPMailer for SMTP and there is problem in sending mail with error "Mailer Error: The following From address failed: no-reply#mydomain.org.uk"
My code is as follows:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "localhost;"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = $email_address;
$mail->FromName = $email_address;
$mail->AddAddress($arrStudent[0]["email"]);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject";
$theData = str_replace("\n", "<BR>", $stuff);
$mail->Body = $theData; // "This is the <b>HTML body</b>";
$mail->AltBody = $stuff;
if (!$mail->Send()) {
$sent = 0;
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
i researched everything and when i debug inside class.smtp.php i found error the function "get_lines()" is returning error value "550 Authentication failed"
The code was working fine previously, i am wondering how this problem came suddenly.
Desperate for some help.
Thanks,
Biplab
public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
require_once('mailer.class.php');
$mailer = new PHPMailer();
//do we use SMTP?
if ( USE_SMTP ) {
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->Host = SMTP_HOST;
$mailer->Port = SMTP_PORT;
$mailer->Password = '';
$mailer->Username = '';
if(USE_SSL)
$mailer->SMTPSecure = "ssl";
}
$mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
$mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );
$mailer->AddAddress($to);
$mailer->Subject = $subject;
//$mailer->WordWrap = 100;
$mailer->IsHTML ( TRUE );
$mailer->MsgHTML($body);
require_once('util.class.php');
$mailer->AltBody = Util::html2text ( $body );
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if ( ! $mailer->Send() ) {
return FALSE;
}
else {
$mailer->ClearAllRecipients ();
$mailer->ClearReplyTos ();
return TRUE;
}
}
I've used like that... SetFrom should be used in place of From... that's your error buddy... :))
try adding belowe line to php.ini
extension=php_openssl.dll
restart and try again
I am using YII's Mailer with PHPMailer, and this works for me:
$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Username = $this->SMTP_USERNAME; // SMTP username
$mail->Password = $this->SMTP_PASSWORD; // SMTP password
$mail->SMTPAuth = true;
$mail->From = $this->fromAddress;
$mail->Host = $this->SMTP_SERVER_ADDRESS;
$mail->FromName = $this->fromName;
$mail->CharSet = 'UTF-8';
$mail->Subject = Yii::t('mailer', $this->subject);
$mail->Body = $this->message;
$mail->AddReplyTo($this->toAddress);
$mail->AddAddress($this->toAddress);
$mail->IsSMTP(true);
$mail->IsHTML(true);
$mail->Send();
Hope that helps?