I'm pretty sure that there are many questions out there regarding this problem.I don't seem to get my solution.
I'm using PHPMailer to mail through my php script.It was totally working few days back but today i tried doing it again,it didn't work.
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$message="Hello there";
$mysqli->autocommit(FALSE);
$statement=$mysqli->prepare("INSERT INTO usertable VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$zero=0;
$null=null;
$state='Delhi';
$statement->bind_param("sssssiiissssi",$email,$firstname,$lastname,$name,$password,$zero,$confirmcode,$zero,$null,$null,$null,$state,$zero);
$statement->execute();
try
{
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support#mydomain.com'; // SMTP username
$mail->Password = 'mvdctadwzkiibtot'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('From #mydomain', 'mydomain');
$mail->addAddress($email); // Name is optional
$mail->addReplyTo('support#mydomain.com', 'For any queries mail back to support#foodquo.com');
// $mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50;
// $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 = 'Confirm your email ID';
$mail->Body = $message;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
}
catch(Exception $e)
{
$mysqli->rollback();
$response=array(
'status'=>'mailFailed',
'errorer'=>$e->getMessage(),
);
}
echo json_encode($response);
NOTE
I have my domain registered on Hostgator.
The email is present inside the cpanel and i can configure it from there.It doesn't have any password.So $mail->Password should not be an issue.
Given Below is the error that i have been getting , what could be the possible solution? Thanks!
SMPT Error :Could not authenticate.
if u are using gmail smptp service use:
$mail->Username = 'emailid#gmail.com'; // Gmail username
$mail->Password = 'mvdctadwzkiibtot'; //gmail password
Related
I know there is several similar threads but I have tried all without any success.
$recipient = ($_POST["to"]);
$mail->AddAddress = ($recipient);
This doesn't work. I have tried with many different combinations as well, like this:
$mail->addAddress = ($recipient, 'name');
I am also running the validate address, which returns true
var_dump(PHPMailer::validateAddress($recipient));
Still I am getting Error: You must provide at least one recipient email address
Any suggestions?
Try this one:
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.mysite.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info#mysite.nl'; // SMTP username
$mail->Password = 'secure123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('info#mysite.nl', 'My cool website'); // The email address of your site goes here
$mail->addAddress('customer#hotmail.com', 'Important customer'); //Destination address and name
$mail->Subject = 'Just saying hi!'; //Title of your mail
$mail->Body = '<h1> A test mail </h1>';
$mail->AltBody = 'Mail has been sent!';
if(!$mail->send()) {
$data = array('mailissend' => false, 'message' => $mail->ErrorInfo);
} else {
echo json_encode('Email is sended');
}
I am working on ticketing system in PHP. I convert mails to tickets. When a user replies to the mail from the Ticketing system, it is sending the mail to the customer as a new mail. No message/mail threading.
I think, my problem is related to the added ticket id at the end of the subject. (e.g. Subject: Installation Problem [#EMSY45])
I have passed the Message ID and References in the Header
I am using PHPMailer to send the mail.
Here is my code:
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = str_replace('/', '', $host); // Specify main and backup SMTP servers
if($outgoing_server_details['smtp_auth'] == 1)
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $outgoing_server_details['server_username']; // SMTP username
$mail->Password = $outgoing_server_details['server_password']; // SMTP password
$mail->SMTPSecure = $protocol; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port;
$mail->setFrom($outgoing_server_details['from_email_field'], $from_name);
$mail->addAddress($data['_from'], $to_name); // Add a recipient
$mail->addReplyTo($outgoing_server_details['from_email_field'], $reply_to_name);
$message_id = $data['message_id'];
$mail->AddCustomHeader('In-Reply-To', $message_id);
$mail->AddCustomHeader('References', $message_id);
//$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 = $data['subject'];
$mail->Body = $mail_content;
$mail->send();
If you need to add ticket ID in the end Subject of the E-Mail then try this.
$mail->Subject = "Installation Problem [".$message_id."]";
OR
$mail->Subject = $data['subject'].$message_id;
And one more Correction
$mail->isHTML(true);//should always come after the Body is set.
i.e.,
$mail->Subject = $data['subject'].$message_id;
$mail->Body = $mail_content;
$mail->isHTML(true);
$mail->send();
I'm close to finishing my first real website, this website uses php mail function to send mail from my website. My script works because I'm running mercury which routes the mail through gmail smtp. Now my question is if someone can tell me how to connect to this smtp server from php because my webhost doesn't allow me acces to the php.ini file.
Thanks in advance
This PHP class will do it for you. Most real webapps don't rely on PHP's mail(), they use this class instead (or swiftmailer, but his one's much easier).
PHPMailer
Sample code (from the linked page)
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.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';
}
So I'm trying to just send some basic email from my site to return forgot passwords. I'm not sure why its not working. I've looked around and tried to jus copy and have also tried modifying others' examples.
<?php
$to = 'temp#yahoo.com';
$subject = 'PHPMAILER';
$message = 'TEST MESSAGE';
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'tls'; // Enable encryption (tls), 'ssl' also accepted
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 587;
$mail->isHTML(true); // Set email format to HTML
$mail->Username = 'temp#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SetFrom = 'webmaster#website.net';
$mail->FromName = 'webmaster';
$mail->WordWrap = 100; // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->Subject = $subject;
$mail->Body = $message;
$mail->addAddress($to,); // Add a recipient
if(!$mail->send()) {
echo 'Message could not be sent.<br>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
I've tested both port 465 and 587. I'm using Hostgator and I think they are restricting port 587 from use so I've been trying to use port 465. I tested the connection with telnet and it worked fine. When I try to go to the page that is in my test.php it returns a white screen until it times out and I receive error 504. I don't know where it goes wrong but hopefully somebody can help. Thank you.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.comcast.net'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mass.mari06#gmail.com'; // SMTP username
$mail->Password = '8489328117'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->Port = $SmtpPort;
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('mass.mari06#gmail.com', 'Joe User'); // Add a recipient
$mail->addAddress('deeparavisankar93#gmail.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$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';
}
?>
****ERROR:**** Message could not be sent.Mailer Error: SMTP connect() failed.
So what can I do? Please help me.. this code I downloaded from GitHub.
SMTP is mail sending server.
You should use the one you are trying to send mail "from" is assigned. I assumed that you try to send from mass.mari06#gmail.com so configuration should look like following:
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mass.mari06#gmail.com';