Hi I am using phpMailer For sending email. Its working fine on server, but when i am trying to send mail from my local machine(localhost) it giving me error. I am using GMAIL smtp
<?
require("lib/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "XXX#XXX.com"; // SMTP username
$mail->Password = "XXXXXXX"; // SMTP password
$mail->From = $email;
$mail->AddAddress("XXXXXX#XXX.com", "XX XX XX");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
}
?>
and the error is
SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
It's working fine in my server.
Okay I got it in local here is the code that I used
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username#doamin.com"; //Reply to this email ID
$email="username#domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
i have sendnewmail function using it send mail,in mail message is send message dispaly but in gmail its not coming ,this is the code
function sendnewmail($msgnew,$emailidnew,$subjectnew){
require_once("class.phpmailer.php");
require_once("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.domain.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username ="user"; // SMTP username
$mail->Password ="password"; // SMTP password
$mail->From = "abcds#gmail.com";
$mail->FromName = "name";
$mail->AddAddress($emailidnew,"sudeshna");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subjectnew;
$mail->Body = $msgnew;
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}else{
echo 'Message send ok';
}
}
$htmldetails ="Welcome to World";
$email = "abc#gmail.com";
$subject = "Sample welcome message";
sendnewmail($htmldetails,$email,$subject);
hope this work
function sendnewmail($msgnew,$emailidnew,$subjectnew){
require_once("PHPMailer/class.phpmailer.php");
require_once("PHPMailer/class.smtp.php");
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "mail.domain.com"; // specify main and backup server
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username ="user"; // SMTP username
$mail->Password ="password"; // SMTP password
$mail->From = "abc#domain.com";
$mail->FromName = "name";
$mail->AddAddress($emailidnew,"sudeshna");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subjectnew;
$mail->Body = $msgnew;
if(!$mail->Send()) {
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}else{
echo 'Message send ok';
}
}
$htmldetails ="Welcome to World";
$email = "tausifahmad810#gmail.com";
$subject = "Sample welcome message";
sendnewmail($htmldetails,$email,$subject);
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
// ---------- adjust these lines ---------------------------------------
$mail->Username = "mymail#gmail.com"; // your GMail user name
$mail->Password = "xxxxxxxxxx";
$mail->AddAddress("yourmail#yahoo.com"); // recipients email
$mail->FromName = "abc"; // readable name
$mail->Subject = "Sample Email";
$mail->Body = "Here is the message you want to send to your friend.";
//-----------------------------------------------------------------------
$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 25;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
Mailer Error: The following From address failed: mymail#gmail.com : Called Mail() without being connected.
How can I fix it??
I am trying to send email/SMTP with PHP from my localhost with WAMP
but it's giving me the following error:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.
(10061)
here is my code:
require_once("./PHPMailer_5.2.4/class.phpmailer.php");
// The message
$message = "hello there!";
$mail = new PHPMailer();
$mail->IsSMTP();; // send via SMTP
$mail->Mailer = 'smtp';
$mail->SMTPDebug=4;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
//$mail->Port = 465;
// $mail->SMTPSecure = 'ssl';
// or try these settings (worked on XAMPP and WAMP):
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = "myemailu#gmail.com"; // SMTP username
$mail->Password = "mypass****"; // SMTP password
$webmaster_email = "myemail#doamin.com"; //Reply to this email ID
$email="ohermail#yahoo.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
i have phpmailer and i can send email via php page without any problem
but the sender automatically by username it i am use in smtp server
i want take sender email from user who write message not from default sender
and this is form code
<?php
require '../../PHPMailer/PHPMailer-master/PHPMailerAutoload.php';
$name = $_POST['name'];
$Institute = $_POST['Institute'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Debugoutput = 'html';
//$mail->SMTPDebug = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "MyGmail";
$mail->Password = "MyGmailPass";
$mail->setFrom('Mygmail', $name);
$mail->addReplyTo('MyGmail', 'First Last');
$mail->addAddress('MyEmail', 'Nasser');
$mail->Subject = 'Database Site Reminder';
$mail->Body = ($message);
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
i am put `$mail->setFrom('Mygmail', $name); this like
$mail->setFrom($email, $name);
because take sender email from user , and i get Message sent
but message not arrive to my email
i cant find any solution... please assist me
thanks ...
$mail = new PHPMailer();
$body = "Body text goes here";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$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 = "Gmail Id"; // GMAIL username
$mail->Password = "PaSsWoRd"; // GMAIL password
$mail->SetFrom('fromemail#gmail.com', 'User');
$mail->AddReplyTo("fromemail#gmail.com","User");
$mail->Subject = "Subject Goes Here";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress('toemail#gmail.com', 'User');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo("Success");
}
try this code... its working....
If you are using PHP Mailer from Github,
then you can set the Sender name by,
$mail->SetFrom("info#mibckerala.org", "MIBC");
Now we are using our own server to send email to our customers. its possible to send email using google server. how to do this. explain with php codes
Download PHPMailer from http://phpmailer.sourceforge.net
Extract to folder phpmailer
Create a file email.php
Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username#doamin.com"; //Reply to this email ID
$email="username#domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
function email($to, $subject, $body){
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "email#domain.com";
$mail->Password = "password";
$mail->SetFrom("anything#domain.com", "Any Thing");
if(is_array($to)){
foreach($to as $t){
$mail->AddAddress($t);
}
}else{
$mail->AddAddress($to);
}
$mail->Subject = $subject;
$mail->Body = $body;
$mail->Send();
unset($mail);
}
Download http://phpmailer.sourceforge.net/ and name it "class.phpmailer.php"
http://micrub.info/2008/09/22/sending-email-with-zend_mail-using-gmail-smtp-services/
http://stackoverflow.com/questions/36079/php-mail-using-gmail