I want to send an email through the website I created but i can't connect with SMTP server with any port. I use windows 8.1, does it matter? If yes, please tell me how to setting SMTP server.
This is my code :
IF(isset($_POST['reply_button']))
{
$tmpEmail=$_POST['email'];
$tmpName=$_POST['name'];
$tmpContent=$_POST['content'];
$message = file_get_contents('mailTamplate/replyMessage.html');
$message = str_replace('%name%', $tmpName, $message);
$message = str_replace('%content%', $tmpContent, $message);
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Username = "example#gmail.com";
$mail->Password = "password";
$mail->AddAddress($tmpEmail);
$mail->FromName = "Example";
$mail->AddEmbeddedImage('./images/logo.jpg', 'my-image', 'attachment', 'base64', 'image/jpeg');
$mail->Subject = $tmpName;
$mail->MsgHTML($message);
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
{
echo "Message has been sent";
}
}
Related
I have implemented mail functionality to my website but getting error while sending email.I have added PHPMailer to my website and added code but getting this error. Changed with host as well by checking in google but still getting the same error.
2019-07-06 06:55:56 CLIENT -> SERVER: EHLO website.com
2019-07-06 06:55:56 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host.
2019-07-06 06:55:56 CLIENT -> SERVER: QUIT
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php
if(isset($_POST['submit_contact']))
{
require 'PHPMailer/PHPMailerAutoload.php';
$to = "XXXX#gmail.com";
$name = $_POST['firstname'];
$email = $_POST['email'];
$contact=$_POST['contact'];
$textarea = $_POST['textarea'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'none';
$mail->Host = "localhost";
$mail->Port = 25;
$mail->IsHTML(true);
$mail->Username = "XXXXX#gmail.com";
$mail->Password = "PASSXXX";
$mail->SSL=False;
$message = array();
$message[]= 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($contact).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Message : '.trim($textarea).' ';
$message = implode('<br/>', $message);
$mail->SetFrom($email);
$mail->Subject = 'Regarding Pure Gir Cow Milk';
$mail->Body = $message;
$mail->AddAddress($to);
if(!$mail->send()) {
$msg = "Error while sending email";
$msgclass = 'bg-danger';
} else {
$msg = 'Successfully Sent.';
$msgclass = 'bg-success';
}
}
?>
This solved my issue.
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'none';
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "xxxx#gmail.com";
$mail->Password = "xxxxx";
$from = $email; // Reply to this email
$mail->From = $from;
$mail->FromName = $name;
I am new at PHP. I am using PHPMailer to send emails but unable to do so. I tried configuring it for gmail and it worked But not working when tried to send msg from remote host and for the given domain.
Here is the code.
<?php
require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file.
$mail = new PHPMailer();
//$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "175.000.000.000"; //Sample Host
$mail->SMTPDebug = 1;
$mail->Port = "25"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
$mail->Username = "maaz#mcbah.com";
$mail->Password = "password";
$mail->From = "maaz#mcbah.com";
$mail->FromName = "Maaz Khan";
$mail->AddAddress("mcbah.all#mcbah.com", "all");
$mail->AddReplyTo("fundprices#mcbah.com", "Fund");
$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;
echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';
exit;
} else {
echo 'Message has been sent.';
}
This code may help you
$mail->Host = "smtpout.secureserver.net";
Your host name should be like mydomain.com
$mail->Port = 465;
is my code correct or give some suggestion for sitemailxchange host and with port number..? i have check most of combination .
Thanks in advance.
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.sitemailxchange.gate.com";
$mail->Port = 587;
$mail->Username = "yourmail#domain.com";
$mail->Password = "password";
$mail->SetFrom('yourmail#domain.com');
$mail->AddReplyTo("yourmail#domain.com");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, viewer!";
$mail->MsgHTML($body);
$address = "yourmail#domain.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I have php code using phpmailer to send two different messages to two users. I have duplicate the code twice to send both mails, but that's makes the process takes long tome to complete the task. is there any solution to make my code more simple
//// -------------------- send email. to student adviser ----------------------------------------------------------
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Username = "rms#gmail.com";
$mail->Password = "12121212";
$mail->AddAddress($advisoremail);
$mail->FromName = "RMS-NCT";
$mail->Subject = "New Request from: ".$_SESSION['UID'];
$mail->Body = "Dear Mr. Adviser you have got new request from 26s12115 ... click here to access it. http://localhost/rms/";
//-----------------------------------------------------------------------
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
// ------------send email to student ----------------------
$mail = new PHPMailer();
$mail->Username = "rms#gmail.com"; // your GMail user name
$mail->Password = "12121212";
$mail->AddAddress($_SESSION['UEMAIL']);
$mail->FromName = "RMS-NCT";
$mail->Subject = "Receipt for your new Request";
$mail->Body = "Dear Student .. Your request has been sent.. you will get response as soon as possible.";
//-----------------------------------------------------------------------
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
As long as you have two different subjects and bodies, I would say no. There is no way to simplify this task.
But you could put the task in one function, that gets the different parameters. So you just have one function to call.
require("phpmailer/class.phpmailer.php");
function send_mail($email, $subject, $body) {
$mail = new PHPMailer();
$mail->Username = "rms#gmail.com";
$mail->Password = "12121212";
$mail->AddAddress($email);
$mail->FromName = "RMS-NCT";
$mail->Subject = $subject;
$mail->Body = $body;
//-----------------------------------------------------------------------
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
}
require("phpmailer/class.phpmailer.php");
function sendMail($to = "trash#domain.com", $subject = "", $body = "", $from = "RMS-NCT")
{
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "rms#gmail.com";
$mail->Password = "12121212";
$mail->From = $mail->Username;
$mail->FromName = $from;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
return false;
}
return true;
}
In code, smth like this:
$Address = $advisoremail;
$Subject = "New Request from: " . $_SESSION['UID'];
$Body = "Dear Mr. Adviser ...";
if (sendMail($Address, $Subject, $Body)) {
echo "Message has been sent";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
I used phpgmailer to send emails and it was working smoothly. Today I tested my project and it's not working now.
<?php
require_once('class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->Username = 'username#gmail.com';
$mail->Password = '********';
$mail->From = 'username#gmail.com';
$mail->FromName = "<blah>";
$mail->Subject = 'something';
$mail->AddAddress('xyz#gmail.com');
$mail->Body = "Hello Sir"."\n"."
Your Password is : ."."";
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Send();
if(!$mail->Send())
{
echo 'Message could not be sent.' ;
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
I suggest you download PHPMailer and try this code:
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "from#gmail.com";
$mail->Password = "****";
$mail->FromName = "Sender name";
$mail->Subject = "test";
$mail->Body = "Test body";
$mail->AddAddress('sender#mail.com');
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message has been sent";
}
#goose is right, remove the first $mail->Send() and leave the one in the if statement. If the From address is the same as the username email, then you don't need that either as it will take it from your gmail account.
Try that and see if it works.
EDIT: try adding the following;
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // 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;
$mail->Username = 'email#gmail.com';
$mail->Password = 'password';
Try that and if there are errors, then it should give you more detail.
EDIT2: If that doesn't work then I suggest trying PHPMailer instead of PHPGmailer - and follow the tutorial here: http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
Please, make sure:
$mail->Username is equal to $mail->From, and is correct
$mail->Password is correct
$mail->FromName does not contain "<" and ">" characters; just try $mail->FromName = 'Test';