PhpMailer: loading a while and then ERR_EMPTY_RESPONSE - php

I am dealing with something strange..
I am setting phpmailer and if I have an error I get the error normally
echo "Mailer Error: " . $mail->ErrorInfo;
actually if everything is good, the page loads a while and then it stops loading, getting in chrome the error: ERR_EMPTY_RESPONSE (Impossible to load the page because the server didn't load the data)
This is the content
<?php
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 645;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myemail#gmail.com"; // SMTP username
$mail->Password = "my password"; // SMTP password
$email = 'myemail#gmail.com';
$mail->From = $email;
$mail->AddAddress("to#example.com", "Name");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject of the mail";
$mail->Body = "content";
$mail->AltBody = "content";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
of course I have included this files:
require_once('../library/class.phpmailer.php');
require_once('../library/PHPMailerAutoload.php');

Two mistakes - just load the autoloader, that loads the class for you so that's all you need.
You've set Port = 645; I suspect you meant 465.
For gmail you should follow the example from the docs: use Port = 587 and SMTPSecure = 'tls'.

you need to Upload the PHPMailer to 6.5.
beacause the php 7.x it's diferent
look that the code change a little bit

Related

phpmailer Error message The domain.com page isn’t working

I have placed phpmailer folder into my public_html folder in my web hosting account, but once i test the code i am not getting any error messages, all i am getting is this message.
The webpage.com page isn’t workingwebpage.com is currently unable to handle this request.
HTTP ERROR 500
here is my code
<?php
require_once("/home/webfolder/public_html/PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = "mail.example.com";
$mail->SMTPAuth = true;
$mail->Username = "test#example.com";
$mail->Password ="password";
$mail->From =("sender#mailer.com");
$mail->FromName = "John Smith";
$mail->AddAddress="test#example.com";
$mail->WordWrap="50";
$mail->IsHTML(true);
$mail->SMTPDebug = 1;
$mail->Port = 26;
$mail->SMTPSecure = "ssl";
$mail->Subject = "Helloworld of SMTP";
$mail->Body = "This is the first email sent from PHP";
$mail->AltBody = "this is alternative mail";
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message has been sent";
}
?>
i have placed this code in a file called testmailer.php outside phpmailer folder so i usually test the code in a path like this
http://domain.com/testmailer.php

Not able to send email via PHP using office 365 smtp. Works on localhost but fails online

$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.

PHPMailer : SMTP host connection error on Godaddy

Mailer Error: SMTP Error: Could not connect to SMTP host.;
this error is generating when i run this code in godaddy.
<?php
require("PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtpout.secureserver.net"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username#domain.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "username#domain.com";
$mail->FromName = "User";
$mail->AddAddress("Sendto#gmail.com"); // name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if (!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
Try below code it's working for me!
<?php
require("src/PHPMailer.php");
require("src/SMTP.php");
require("src/Exception.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
//Recipients
$mail->setFrom('from#gmail.com', 'Mailer');
$mail->addAddress('to#gmail.com', 'XYZTABC');
//Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "<pre>";
print_r($e);
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
If i understand correctly, using the SMTP address you are using you need to specify the port too (465).
However, according to the godaddy documentation, you should be using the following SMTP server:
relay-hosting.secureserver.net
This code may help you.
$mail->Host = "smtpout.secureserver.net";
your host name should be like mydomain.com
$mail->Port = 465;
i solved this using localhost as smtp server, port 25, no ssl and no authentication.
I'm using wordpress, with divi theme on a godaddy server.

PHPMailer error: Could not instantiate mail function

I've looked through all the old posts on stackoverflow and many on other websites and find lots of posts with the same error, but none of the fixes work.
The following is the error I get:
Mailer Error: Could not instantiate mail function.
Is there something missing or incorrect?
<?php
require '../PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "censored#gmail.com";
$mail->Password = "censored";
$mail->setFrom('censored#gmail.com');
$mail->addReplyTo('censored#gmail.com');
$mail->addAddress('censored#gmail.com');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I found what you're missing.
You need to set these 2 things to get it to work properly:
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';

PHPMailer still sending emails infinitely

I am using PHPMailer to send emails.
When I execute the code that sends an email to X#Y.Z, I still receive this email, not only onetime, but each time I refresh my inbox I receive many copies of it!
Note: I execute the code one time only!!
So what's wrong?
this is my code:
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = "bla blas";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "xxx.xxx.xxx.xxx";
$mail->Port = 25;
$mail->Username = "****";
$mail->Password = "****";
$mail->SetFrom('z#z.z');
$mail->AddReplyTo("z#z.z");
$mail->Subject = "test";
$mail->MsgHTML($body);
$mail->AddAddress('X#Y.Z');
if(!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//echo "Message sent!";
}
Thanks!

Categories