I'm trying to send some mail using php mailer, the boring thing is that one email eas sent the first time and I have no idea what I've done that makes this code to now fail.
ERROR: SMTP server error: authentication required
require("../mailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->From = "site email";
$mail->AddAddress("useremail");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
I'm hosting with GoDaddy.
Thanks to Jake.
Incase someone goes through this again here is what i put in my code.
CODE
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->Username = "email#domain";
$mail->Password = "pwd";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->SMTPDebug = 2; /// i guess this is for reporting...
$mail->From = "email#domain";
$mail->AddAddress("recipient email");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
Related
Here is my code below. But it keeps ending up in spam
I already added authentication and changed the setfrom address but it still ends up in spam
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
// $mail->SMTPAutoTLS = true;
$mail->Username = '******'; // SMTP username
$mail->Password = "******";
$mail->Port = 25;
$mail->setFrom('info#canbeltech.com', 'Canbel Tech');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = 'Canbel Tech IMT Biometric Card Receipt';
$mail->Body = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
exit;
The below function to send email but got any mail or error :
function send_Email($email, $subject, $body ,$cc = '')
{
$this->Log("Sending email with To: ". $email. " <br>Subject: ". $subject ." <br>Body: ".$body);
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->CharSet = "utf-8";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = email_host;
$mail->Username = email_username;
$mail->Password = email_password;
$mail->SetFrom('support#xyv.com', 'zzz Support');
$mail->AddReplyTo('support#xyv.com', 'zzz Support');
$mail->AddAddress($email);
$mail->AddBCC('support#xyv.com');
$mail->AddBCC('zzz#zzz.com');
if(!empty($cc)) {
$mail->addCC($cc);
}
$mail->Subject = $subject;
$mail->Body = $body;
echo "<pre>"; print_r($mail);echo "</pre>";
$response = $mail->Send();
var_dump($response);
return $response;
}
Debug : IN DEBUG MODE NOT GET ERROR
[error_count:protected] => 0
It would really help to read the docs and base your code on the examples provided, which show how to get info about errors, and show debug output. You're not getting any output because you're not asking for any. From the example in the readme:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
That will show you the reason for any sending failure. To enable SMTP debug output, do this:
$mail->SMTPDebug = 2;
<?php
require_once 'PHPMailer-master/class.phpmailer.php';
require_once 'PHPMailer-master/class.phpmaileroauthgoogle.php';
require_once 'PHPMailer-master/PHPMailerAutoload.php';
require_once 'PHPMailer-master/class.smtp.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = TRUE;
//$mail->SMTPDebug =2;
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'zhaider113#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 587;
$from = 'shahghafoor439#gmail.com';
$mail->setFrom($from, 'Ghafoor Shah');
$mail->addReplyTo($from, 'Ghafoor Shah');
$mail->addAddress('zhaider113#gmail.com', 'zeeshan');
$mail->Subject = 'This is subject';
$mail->Body = 'This is the body of email';
$mail->AltBody = 'This is the body of email';
$mail->send();
if (!$mail->send()) {
echo 'Messag could not send';
echo 'Mailer error:' . $mail->ErrorInfo;
} else {
echo 'mail hasbeen send';
}
?>
I try to send email but it not send and give error message which is:SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting */
try with $mail->SMTPSecure = 'tls';
See full example at PHPMailer's gmail example below: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
Make sure you include correct PHPMailer Library.
And make this changes
Some Servers not response for SSL(Secure). So that change this $mail->SMTPSecure = 'tls';
And In your code you have two Mail sending option $mail->send();
//$mail->send();//Comment this
if (!$mail->send()) {
echo 'Messag could not send';
echo 'Mailer error:' . $mail->ErrorInfo;
} else {
echo 'mail hasbeen send';
}
Now either mail sent Or either It will print Error log
I don't know if my code is the issue or if I had configured Zoho's SMTP's settings incorrectly.
Basically I want the ability to dynamically send emails with a simple php function like for example
phpMail("to#example.com", $subject, $body, "from#example.com", "replyto#example.com");
This is my PHPMailer.php script (it sees the function and its settings)
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '**REMOVED**'; // SMTP username
$mail->Password = '**REMOVED**'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->isHTML(true); // Set email format to HTML
// SYTAX: phpMail($from, $reply, $to, $subject, $body);
function phpMail($to, $subject, $body, $from = "from#example.com", $reply = "replyto#example.com") {
if (isset($from))
$mail->From = $from;
$mail->FromName = "testing";
if (isset($to))
$mail->addAddress($to);
if (isset($reply))
$mail->addReplyTo($reply);
if (isset($subject))
$mail->Subject = $subject;
if (isset($body))
$mail->Body = $body;
$mail->AltBody = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
Now the issue with this is that, I'm not receiving emails nor am I receiving any errors / messages but it's also not sending me an email.
When you make a PHP function, make sure your objects aren't outside of your function.
My error wasn't that though, it was basically my own stupidity which had nothing to do with the code but more of my "form post data".
The following configuration works for me using zoho mail.
Give it a try:
$mail=new JPhpMailer;
$mail->IsSMTP();
$mail->Host='smtp.zoho.com';
// Enable this option to see deep debug info
// $mail->SMTPDebug = 4;
$mail->SMTPSecure = 'ssl';
$mail->Port='465';
$mail->SMTPAuth=true;
$mail->Username='your_email_address';
$mail->Password='your_eamil_address_password';
$mail->isHTML(true);
$mail->SetFrom('your_email_address','Your Name');
$mail->Subject='PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody='To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress('destination_email_address','John Doe');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I use this code to send an email:
When I open the mail.php file in my browser. Nothing will send. The browser will load a blank page with no message displayed saying the email was sent. I have been searching on StackOverflow and other websites for a solution. Can someone help me?
<?php
require_once("phpmailer\class.phpmailer.php");
// path to the PHPMailer class.
require_once("phpmailer\PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = "25";
// 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
// Uncomment this line if you want to use SSL.
$mail->Username = "emailer#my.domain";
$mail->Password = "password";
$mail->From = "example#gmail.com";
$mail->FromName = "Susan Sender";
$mail->AddAddress("rachel#my.domain", "Rachel Recipient");
//$mail->AddReplyTo("Your Reply-to Address", "Sender's Name");
$mail->Subject = "Hi!";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
}
else {
echo 'Message has been sent.';
}
?>