PHPmailer mailer in herokku giving HTTP ERROR 500 - php

I made a code that sends mail using SMTP gmail with phpmailer. It worked fine in my local host.But when I deployed the code in heroku it is giving
royalmarutiservices.herokuapp.com is currently unable to handle this request.
HTTP ERROR 500
Here is the log of heroku
https://pastebin.com/raw/AgY11dBB
<?php
//echo $_POST['email'].$_POST['fname'].$_POST['phone'].$_POST['subject'];
include_once('PHPMailer/src/PHPMailer.php');
include_once('PHPMailer/src/SMTP.php');
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // 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; // or 587
$mail->IsHTML(true);
$mail->Username = "user#gmail.com";
$mail->Password = "pass";
$mail->SetFrom($_POST['email']);
$mail->Subject = " Message from ".$_POST['fname'];
$mail->Body = $_POST['message'];
$mail->AddAddress('royalmaruti1996#gmail.com');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
header('Location:index.php');
?>
Details about phpinfo()
~ https://royalmarutiservices.herokuapp.com/info.php

Related

Can't send email using PHPMailer using Gmail(Failed to connect server)

i'm trying to send an email using PHPMailer. I've seen some topics about sending an email by Gmail servers using this package but i couldn't succeed.
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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 = 587; // or 587
$mail->Username = "myEmailAddress#gmail.com";
$mail->Password = "MyGmailPassword";
$mail->setFrom('myEmailAddress#gmail.com', 'First Last');
$mail->addAddress('MyTargetEmail#example.com', 'John Doe');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = 'Text to be sent';
if(!$mail->send()){
echo 'message was not sent: ' . $mail->ErrorInfo;
}
else{
echo 'Successfully sent';
}
my response :
2018-11-29 14:56:37 SMTP ERROR: Failed to connect to server: (0)
<br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<br>
message was not sent: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
You are sending the email to the wrong port/configuration. In your code you have it sent to Port 587 which handles stmp connections but you are sending it configured over ssl (which would need to be sent over port 465).
You ONLY need to change where it says ssl to "tls" and it will work.
$mail->SMTPDebug = 2; // 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; // or 587
Try this with composer
require phpmailer/phpmailer
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;enter code here
$mail->Username = '#gmail.com';
$mail->Password = '';
$mail->setFrom('#gmail.com', '');
$mail->addReplyTo('#gmail.com', '');
$mail->addAddress('#gmail.com', ' Name');
$mail->Subject = 'This for Testing PHPMailer';
//$mail->msgHTML(file_get_contents('message.html'), __DIR__);
$mail->Body = 'This is a plain text message body';
//$mail->addAttachment('test.txt');
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'The email message was sent.';
}
?>

how to send Email by date automatic

I have this source code and it works well, but I want to send emails by date
such as
(Today date == date from DB)
{
Code send
}
How can I send it automatically, I don't want to reload the page.
My source code:
`<`?php
include "classes/class.phpmailer.php"; // include the class name
$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 = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "gmailusername#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("anyemail#gmail.com");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "<b>Hi</b>";
$mail->AddAddress("anyaddrees#domain.com");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
?>
you could use Task scheduler on windows or cronjob on linux. Also as "Jan" said in the comment could you please provide more info.

PHPMailer is not working at all

I'm trying to configure PHPMailer I've uploaded 1 file which is class.phpmailer.php and created another php file with this content:
<?php
require('class.phpmailer.php');
$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 = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
and i get nothing at all not a success message nor a failure message. http://www.mawk3y.net/mailtest/test.php
all answers are outdated now. Most current version (as of Feb 2018) does not have autoload anymore, and PHPMailer should be initialized as follows:
<?php
include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
include_once(FCPATH.'PHPMailer/src/SMTP.php');
include_once(FCPATH.'PHPMailer/src/Exception.php');
$msj="My complete message";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
//authentication SMTP enabled
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
//indico el puerto que usa Gmail 465 or 587
$mail->Port = 465;
$mail->Username = "xxxxxx";
$mail->Password = "xxxx";
$mail->SetFrom("xxxxxx#xxxxx.com","Name");
$mail->AddReplyTo("xxx#xxx.com","Name Replay");
$mail->Subject = "Test";
$mail->MsgHTML($msj);
$mail->AddAddress("xxxxxx#xxxxx.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
The problem is with the require method.
You first have to extract all file of phpMailer repository.
instead of writing
require('class.phpmailer.php');
you need to include path where your PHPMailerAutoload.php file extracted.so you can replace it with.
require('path-of-extracted-folder/PHPMailerAutoload.php');
for more reference you can visit it's GitHub link
https://github.com/PHPMailer/PHPMailer
I had same problem but I solved.This is the way I code
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc#gmail.com'; // SMTP username
$mail->Password = 'abc'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Set who the message is to be sent from
$mail->setFrom('abc1#gmail.com', 'First Last');
//Set an alternative reply-to address
//Set who the message is to be sent to
$mail->addAddress('abc#gmail.com', 'Shehan');
//Set the subject line
$mail->Subject = 'Test Mail';
$mail->Body = 'This is Test Mail';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>

PHPMailer Could not Authenticate

I got this error using PHPMailer:
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
and Here is the code :
function send_email($reciever = "e.salamati.taba#gmail.com", $mail_arr = '') { // This function will be upgraded later
$mail = new PHPMailer();
$body = $mail_arr['body'];
//$body = eregi_replace("[\]", '', $body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = true;
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "TLS"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "user"; // GMAIL username
$mail->Password = "pass"; // GMAIL password
$mail->SetFrom('e.salamati.taba#gmail.com', 'no-reply gmail.com');
$mail->Subject = $mail_arr['subject'];
$mail->MsgHTML($body);
echo "-----------------------";
$address = $reciever;
$mail->AddAddress($address, "e.salamati.taba#gmail.com");
if(! $mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
I have also see this, but still got the error, Is there any xampp config or something that cause the problem?
Thanks in advance...

SMTP Gmail Server SSL Error

I used this coding to send mail using gmail, but am getting the below error, here when i removed the ssl part, its working, but i dint receive any emails(checked inside spam also). Any other problems ?
$mail = new phpmailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1;// enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "un"; // GMAIL username
$mail->Password = "pwd"; // GMAIL password
$mail->SetFrom('test#gmail.com', 'Bharanidharan');
$mail->AddReplyTo("test#gmail.com","Vishal Kumar");
$mail->AddAddress("test#gmail.com","Bharani");
$mail->Subject = "Hey, check out";
$body = "hey, check email";
$mail->MsgHTML($body);
$address = "test#gmail.com";
$mail->AddAddress($address, "test");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
Enable the mod_ssl in Apache (search the config file) and the openssl PHP extension (check php.ini)

Categories