phpMailer with smtp - phpmailer

I have this piece of code:
ini_set('SMTP','smtp.strato.com');
$mail = new PHPmailer();
$mail->IsHTML(true);
It works fine but can I set smtp.strato.com somewhere in phpMailer class?

Have you looked at the smtp example in their site? See here
Unless I'm miss understanding you, it looks to be very straight forward.
$mail = new PHPMailer();
$body = "message";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("whoto#otherdomain.com", "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

You can by changing
$mail->IsSMTP();
$mail->Host = "mail.yourdomain.com";
to
$mail->IsSMTP();
$mail->Host = "smtp.strato.com";
You shouldnt modify the PHPMailer class

//Use this codd to send email using SMTP gmail
<?php
require "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth="login";
$mail->SMTPSecure="ssl";
$mail->Username = "sender#gmail.com";
$mail->Password="password";
$mail->Body="<Body message>";
$mail->MsgHTML=("<h1>Wow Html contents</h1>");
$mail->AddAttachment("Koala.jpg");
$mail->SetFrom("sender#gmail.com","Bucky");
$mail->Subject="My Subject";
$mail->AddAddress("receiver#gmail.com");
if ($mail->Send()){
echo "Sent";
}else
echo "not sent<br>";
echo $mail->ErrorInfo;
?>

Related

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'bobbygotecha07#.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'bobbygotecha07#example.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->SMTPSecure = 'ssl';
$mail->setFrom('bobbygotecha07#gmail.com', 'bobby gotecha');
//$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('bobbygotecha07#gmail.com'); // Name is optional
$mail->addReplyTo('bobbygotecha07#gmail.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
This is the code that's been written by me for sending the mail but its not working for me and i have also tried varoius thing thats been mentioned in stackoverflow but its not woking and i have also updated the dll file but still not able to send so if anybody could help me.

PHPMailer isn't working

require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure="tls";
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 587;
$mail->Username = "********#yahoo.com";
$mail->Password = "*****";
$mail->SetFrom('*********#yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('*********#yahoo.com', 'my name');
if($mail->Send()) {
echo "Message sent!";
}else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
So, I try to send an Email with PHPMailer, but the code it does not work,the localhost page isn't working. I copied class.phpmailer.php and class.smtp.php to /var/www/html folder (Before I specified the path in require_once (/usr/share/...)). I enabled ssl extension. I use Ubuntu 16.04 and I installed libphp-phpmailer. What should I do? (Any options to send mail with smtp would be apreciated, already tried: postfix and sendmail).
go through the above comment link..!!
try this
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "******#gmail.com";
$mail->Password = "*******";
$mail->SetFrom('aswad#yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('aswad#yahoo.com', 'my name');
if($mail->Send()) {
echo "Message sent!";
}else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
try to comment the
$mail->IsSMTP();
line
also check the SELinux config
on the shell type
sestatus -b | grep sendmail
if you see that
httpd_can_sendmail off
just type this 2 lines:
restorecon /usr/sbin/sendmail
setsebool -P httpd_can_sendmail 1

PHPMailer didn't send email message

I try to send email with PHPMailer but getting error.I use port 465 and 587 both are getting error also in SSL and TLS. Error like bellow
2016-06-09 18:55:06 Could not instantiate mail function. Message could not be sent.Mailer Error: Could not instantiate mail function.
How can i solve this and can send email message.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'nuralam862#gmail.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = 'nuralam862#gmail.com';
$mail->FromName = 'nuralam';
$mail->addAddress('nuralam862#gmail.com', 'nuralam');
$mail->addReplyTo('nuralam862#gmail.com', 'nuralam');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->SMTPDebug = 1;
$mail->Subject = 'Using PHPMailer';
$mail->Body = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
First up, you're using an old version of PHPMailer and you need to read the docs. Get the latest.
Because you're using SMTP directly, you don't need a local mail server.
If you increase SMTP debug output you'll be able to see what responses you're getting from the server, which is very likely to be an authentication problem, as described in the troubleshooting guide.
$mail->SMTPDebug = 2;

phpmailer No Relay Access Allowed Error

My website is hosted on godaddy, and I just figured out that my website is no more sending emails through phpmailer since last few months. I uploaded the latest version of phpmailer but still no success. The online web mail of my website runs fine. If I use php's "mail" function, it does send emails to gmail, but not to yahoo accounts.
I tried all the three ports 25, 465, and 587, but no luck
I am getting the following error from phpmailer:
SERVER -> CLIENT: 554 p3plsmtpa07-10.prod.phx3.secureserver.net ESMTP No Relay Access Allowed From 50.63.196.51
CLIENT -> SERVER: EHLO lostandfound.pakproject.com
SERVER -> CLIENT:
SMTP ERROR: EHLO command failed:
SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Following is my code that I am trying to test. (User name, passwords, emails are changed...)
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtpout.... my_server";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "here_i_used_my_website_email";
$mail->Password = "here_password";
$mail->setFrom('website_email', 'From name');
$mail->addReplyTo('website_email', 'From name');
$mail->addAddress('another_email', 'name_used_here');
$mail->Subject = 'About the task';
$mail->Body = 'This is email body';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
It worked for me.
Keep in mind
https://co.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071**
I was able to resolve my issue with the following code/settings of phpmailer
<?php
$recipient = "abc#def.com"
$subject = "Subject here";
$emailBody = "This is body";
// PHP MAILER CODE STARTS FROM HERE //
require '../phpmailermaster/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtpout.secureserver.net'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx#yyyy.com'; // SMTP username
$mail->Password = '3344123'; // SMTP password
//$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 465;
$mail->Port = 80; // TCP port to connect to [THIS PORT ALLOWING EMAILS]
$mail->setFrom('xxx#yyyy.com', 'hello');
//$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress($recipient); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $emailBody;
$mail->AltBody = $emailBody;
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent';
}
// PHP MAILER CODE ENDS HERE ==
?>

How to get SMTP host for my phpmailer

I own my domain .com and it is hosted in different provider of the domain.
And I want to use PhpMailer, but my webhosting doesn't provide me SMTP server but it allows me to create emails of my domain (e.g. sdfsdfsfd#mydomain.com)
So, I really can't use phpmailer because it never connects to SMTP server, what should I do?
I brought my domain in onlydomains and my webhost is 000webhost.
<?php
require './PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#mydomain.com'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = 'noreply#mydomain.com';
$mail->FromName = 'Admin';
$mail->addAddress('sdfsdf#hotmail.com'); // Name is optional
mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'swag';
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Initially download the php mailer files to your sever(if not downloaded before) & define as following.Avoid using net sources in your code.Once you apply this it will work fine and the mail would be sent as from your mail id.
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPDebug = true;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Port = 465; // SMTP Port
$mail->Username = "your mail id"; // SMTP account username
$mail->Password = "password"; // SMTP account password
//The following code allows you to send mail automatically once the code is run
$mail->SetFrom('to mail id', 'name'); // FROM
$mail->AddReplyTo('mail id', 'name'); // Reply TO
$mail->AddAddress('recipient id'); // recipient email
$mail->Subject = "First SMTP Message"; // email subject
$mail->Body = "Hi! \n\n some text.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
After doing the above code if you still not able to send mail means do the following:
In class.smtp.php file add the below given two lines before the line "Connect to the SMTP server" & it ll work fine.
$host = "ssl://smtp.gmail.com";
$port = 465;

Resources