So earlier this week I was asking how to send mail using a SMTP like hMailServer and somehow I got to work locally (however it suddenly requires password and username).
Now I tried to send mail via gmail's smtp server but I can't seem to make it work. There is no error messages and the mail is not being sent. May I know what have I done wrong?
CODE1 - localhost SMTP works
if ($ways=="cashchequesc"){
$_SESSION['youdont'] = "0";
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Username = "admin#127.0.0.1.";
$mail->Password = "password123";
$mail->From = ("pie-company#gmail.com");
$mail->FromName = ("Pie D-licious");
$mail->AddAddress("pielover2014#gmail.com","Valued Customer");
$mail->Subject = $myusername . "'s Purchases of ". $_SESSION['amount'] ." of XXXX.";
$mail->Body = $userIName . " owner/user of account " . $myusername ." has purchased " . $_SESSION['amount'] . " (quantity) of X item(s). Total amount of S$" .
$ _SESSION["payamount"] . ". Payment will be made through Cash/Cheque on Collection";
$mail->WordWrap = 70;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
CODE 2 - Gmail SMTP (doesn't work)
else if ($ways=="netssc"){
$_SESSION['youdont'] = "0";
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->Username = "pie-company#gmail.com";
$mail->Password = "ilovebigpie-chipsdontlie19472013";
$mail->From = ("buymy.pie#gmail.com");
$mail->FromName = ("Pie D-licious");
$mail->AddAddress("pielover2013#gmail.com","Valued Customer");
$mail->Subject = $myusername . "'s Purchases of ". $_SESSION['amount'] ." of XXXX.";
$mail->Body = $userIName . " owner/user of account " . $myusername ." has purchased " . $_SESSION['amount'] . " (quantity) of X item(s). Total amount of S$" .
$_SESSION["payamount"] . ". Payment will be made through NETS/Bank Transfer.";
$mail->WordWrap = 70;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
Related
Here is my code below. But it keeps ending up in spam
I already added authentication and changed the setfrom address but it still ends up in spam
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
// $mail->SMTPAutoTLS = true;
$mail->Username = '******'; // SMTP username
$mail->Password = "******";
$mail->Port = 25;
$mail->setFrom('info#canbeltech.com', 'Canbel Tech');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = 'Canbel Tech IMT Biometric Card Receipt';
$mail->Body = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
exit;
I'd like to send mails via phpmailer and I'd like to get the name from the database for mail body with looping, but my code doesn't work. It keeps on getting the same name for every single mail. Here's my code:
<?php //Library require("phpmailer/classes/class.phpmailer.php");
//Database
$server = "localhost";
$username = "mydatabase_admin";
$password = "localadmin123";
$database = "mydatabase";
//Connect to database
$dbConnection = mysqli_connect($server, $username, $password, $database);
//Check connection
if ($dbConnection -> connect_error) {
echo "Connection Failed";
die ($dbConnection -> connect_error);
}
//Select database and data
$sql = "SELECT * FROM userdata";
$result = $dbConnection -> query($sql);
//Mailing
//Sender information
$mail = new PHPMailer();
$mail->SMTPDebug = 0;
//Use SMTP
$mail->IsSMTP();
$mail->SMTPAuth = true;
//SMTP Server
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
//SMTP Account
$mail->Username = "my_mail#gmail.com";
$mail->Password = "********";
//Automated Mail
$mail->SetFrom('tphp43598#gmail.com', 'Admin');
//Recipient info
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc())
{
$mail->AddAddress($row["Email"]);
$mail->Subject = "Product Review Reminder";
$mail->Body = "Hi ". $row["Full Name"] .",". "\n \nJust a reminder that you need to review the product coded ". $row["Product Handled"] . ".\n" . "Thank You";
}
}
//Output shown if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo "\n" . 'Message has been sent.';
} ?>
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc())
{
$mail->AddAddress($row["Email"]);
$mail->Subject = "Product Review Reminder";
$mail->Body = "Hi ". $row["Full Name"] .",". "\n \nJust a reminder that you need to review the product coded ". $row["Product Handled"] . ".\n" . "Thank You";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo "\n" . 'Message has been sent.';
}
}
}
You are calling sendmail() function outside while loop you are getting name variable whichever is last record. keep inside while loop.
Or if you need to track each individual mail send status then keep array of status. Keep pushing message into status array.
I am getting "Mailer Error: SMTP connect() failed." while sending email using elasticemail host. I tried everything but unable to rectify this error from the code. can someone please help me.
$email = 'myemail#gmail.com';
$password = '**********';
$to_id = 'contact#myemail.com';
$message = 'hello';
$subject = 'hello#12';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp25.elasticemail.com';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $email;
$mail->Password = $password;
// Email Sending Details
$mail->addAddress($to_id);
$mail->Subject = $subject;
$mail->msgHTML($message);
// Success or Failure
if (!$mail->send()) {
$error = "Mailer Error: " . $mail->ErrorInfo;
echo '<p id="para">'.$error.'</p>';
}
else {
echo '<p id="para">Message sent!</p>';
}
?>
I have this form, that send fine locally, but when i upload it to hostgator i get the following error message
Mailer Error: Could not instantiate mail function.
my php code is
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****#*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****#*****.com');
$mail->From = "****#*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>
I have spoken to my host and they said its not within there support to deal with these things, but said my port and host are correct.
So now I'm rather confused. is there anything obvious I'm missing?
Just to let you know if anyone finds this, my problem was i was missing $mail->IsSMTP(); from my config.
the SMTP config section should be as follows
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->IsSMTP();
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****#*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****#*****.com');
$mail->From = "****#*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>
I'm trying to send some mail using php mailer, the boring thing is that one email eas sent the first time and I have no idea what I've done that makes this code to now fail.
ERROR: SMTP server error: authentication required
require("../mailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->From = "site email";
$mail->AddAddress("useremail");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
I'm hosting with GoDaddy.
Thanks to Jake.
Incase someone goes through this again here is what i put in my code.
CODE
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->Username = "email#domain";
$mail->Password = "pwd";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->SMTPDebug = 2; /// i guess this is for reporting...
$mail->From = "email#domain";
$mail->AddAddress("recipient email");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}