require("phpmailer.inc.php");
class sendmail
{
public static function sendAccountActivateMail($to,$subject,&message)
{
$flg = false;
try
{
$mail= new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth= true;
$mail->SMTPSecure= "tls";
$mail->Host= "smtp.gmail.com";
$mail->Port= 587;
$mail->Username= "xxx#mydomain.com";
$mail->Password= "xxxxxx";
$mail->AddReplyTo("info#mydomain.com");
$mail->From= "info#mydomain.com";
$mail->FromName= "Website";
$mail->Subject= $subject;
$mail->WordWrap= 50;
$mail->Body = $message;
$mail->AddAddress($to);
$mail->Send();
}
catch(Exception $e)
{
$flg = false;
}
return $flg;
}
}
Trying to send mail through phpmailer with smtp.
turning on debug gives me error:
SMTP -> ERROR: RCPT not accepted from server: 550 SMTP AUTH is required for message submission on port 587 SMTP -> ERROR: DATA command not accepted from server: SMTP -> NOTICE: EOF caught while checking if connected
It looks like port 587 is blocked. Try using
$mail= new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth= true;
$mail->SMTPSecure= "ssl";
$mail->Host= "smtp.gmail.com";
$mail->Port= 465;.....
Related
I am using PHPMailer to send mails with Google_Service_Gmail,but mails are not getting delivered although status is showing SENT.I have created a valid OAth Credentails for Gmail api,which did deliver 5 mails,but then stopped sending mails,although status is showing as SENT
Using Google_Service_Gmail with PHPMailer
try {
$mail = new PHPMailer();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->CharSet = "UTF-8";
$mail->From = $sender;
$mail->FromName = $alias;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $messageText;
$mail->IsHTML(true);
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$message = new Google_Service_Gmail_Message();
$message->setRaw($mime);
$client = getClient();
$service = new Google_Service_Gmail($client);
$message = $service->users_messages->send($sender, $message);
if ($message->labelIds[0] == "SENT") echo 'Message with ID: ' .$message->getId()."-".$message->labelIds[0];
else echo "Something went wrong...";
return $message;
} catch (Exception $e) {
print "Error" . $e->getMessage();
}
// return null;
}
Returns
Message with ID: 1845b21052f00d8e-SENT
but the e-mail is not delivered.
Guys I Got his error it is working # localhost but does't work on my host
http://myownprojects.co.nf/ ??
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "webdeveloper.hadi#gmail.com";
$mail->Password = '**********';
$mail->setFrom("webdeveloper.hadi#gmail.com");
$mail->Subject= "Your confirmation Mail";
$mail->AddEmbeddedImage('images/me.jpg', 'meimg', 'images/me.jpg');
$mail->Body = "Please click on the link";
$mail->addAddress(webdeveloper.hadi#gmail.com);
if($mail->Send()){
}else{
}
Try the following:
$mail->SMTPSecure = "tls";
$mail->Port = 587;
I can not send mail using the PHPMailer lib. My site is hosted on dreamhost,
with SMTP gmail I can send more properly to the configuration provided by the hosting the only return is:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed.
My code:
<?php
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = trim(stripslashes($_POST['name']));
$from = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'mail.example.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'e-mail#example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->setFrom($from, $name);
$mail->addReplyTo($from, $name);
$mail->addAddress('email#example.com');
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
`
I managed to solve the problem, first replaces the e-mail sent to an e-mail sender#example.com own client, then tried some documentation of dreamhost, made the necessary changes, the code:
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$subject = trim(stripslashes($_POST['subject']));
$name = trim(stripslashes($_POST['name']));
$from = trim(stripslashes($_POST['email']));
$body = trim(stripslashes($_POST['message']));
$mail = new PHPMailer;
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 1;
$mail->Host = 'mail.example.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'sender#example.com.br';
$mail->Password = 'password';
$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->setFrom('sender#dexample.com.br', 'DontAnswer');
$mail->addReplyTo($from, $name);
$mail->addAddress('contact#example.com.br');
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
In dreamhost documentation says it should be repeated sending e-mail in setFrom () method; after these changes the form worked perfectly.
Hi i am trying to send an email using gmail credentials and calling an email template but it is throwing an exception that Failure sending mail
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu#gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
message = new MailMessage();
message.Subject = "Visitor Arrived";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.Body = "EmailTemplate.html";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu#gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(message);
Please help me out.
You have to use StreamReader to read from html file....and also set the MailMessage.BodyFormat property to MailFormat.Html
Use This:
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu#gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your
{ // HTML file
message = new MailMessage();
message.Subject = "Visitor Arrived";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu#gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.Body = reader.ReadToEnd(); // Load the content from your file...
//...
}
SmtpServer.Send(message);
Answer partially taken from Send a email with a HTML file as body (C#)
use port 465 instead
Port 465 is for smtps
SSL encryption is started automatically before any SMTP level communication.
Port 587 is for msa
It is almost like standard SMTP port. MSA should accept email after authentication (e.g. after SMTP AUTH). It helps to stop outgoing spam when netmasters of DUL ranges can block outgoing connections to SMTP port (port 25).
foreach (GnrDataMailInfo dmi in lstDMI)
{
MailMessage mail = new MailMessage();
mail.From = "youremail";
SmtpClient smtp = new SmtpClient();
smtp.Port = 25; // [1] port
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential(mail.From.ToString(), "password"); // [4] Added this.
smtp.EnableSsl = false;
smtp.Timeout = 20000;
smtp.Host = "yourhost";
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.HeadersEncoding = System.Text.Encoding.UTF8;
mail.Subject = dmi.Subject;
mail.To.Add(dmi.To);
mail.IsBodyHtml = true;
mail.Body = dmi.Body;
smtp.Send(mail);
}
I am using phpMailer i do not know whats wrong with my code, it return fails after execution?
my function which call the phpmailer.php page and takes parameters:
function sendEmail($to,$from,$sender_name="",$subject,$body,$attachement_path){
require("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$host="mail.mysite.com";
$userName="info";
$password="password!";
$mail->IsSMTP(); // set mailer to use SMTP i.e. smtp1.example.com;smtp2.example.com
$mail->Host = $host; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $userName; // SMTP username i.e email id of an email address
$mail->Password = $password; // SMTP password for the specified email address
$mail->From = $from;
$mail->FromName = $sender_name;
$mail->AddAddress($to); //mail,name
$mail->AddAddress("myBCCMailAddress#gmail.com"); // name is optional
$mail->AddReplyTo($to);//to, name
$mail->WordWrap = 50;
$mail->AddAttachment($attachement_path);
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
return false;
}
else{
return true;
}
}
Here is the calling method of my above function:
if(sendEmail($to,"info#mysite.com","My Company Name",$subject,$body,$path)){
echo 'mail sent';
}
else{
echo('mail failed to send '.$to);
}
Here is the script i use.
// phpmailer is required earlier
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->isHtml(true);
$mail->AddAddress($customer_email);
$mail->From = 'billing#example.com';
$mail->FromName = 'MyName';
$mail->Sender = 'mailman#example.com';
$mail->AddBcc('accounting#example.com);
$mail->Subject = 'Invoince;
$mail->Body = 'Some exiting text explaining the customer about his invoice';
$mail->AddAttachment('/var/invoices/'.$invoce_nr.'.pdf', 'Faktura.pdf');
$mail->Body = iconv("UTF-8", "ISO-8859-1",$mail->Body);
if($mail->send()){
return true;
} else {
return false;
}
Also make sure you can send regular emails and then make sure the file you are trying to send is readable.