This question already has answers here:
Send email using the GMail SMTP server from a PHP page
(16 answers)
Phpmailer using smtp with Gmail not working - connection timing out
(8 answers)
PEAR Mail unable to connect to Gmail SMTP, failed to connect to socket
(9 answers)
PHPMailer with GMail: SMTP Error
(2 answers)
Closed 4 years ago.
Im trying to send an email on localhost(wamp) but it gives me the error on top!
I also tried with 'tls' and port 587 but same error
my email is configured to receive insecure connection and Imap option is activated ..
pls help me , I need this for school project
<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 2;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; /* or 587;*/
$mail ->IsHTML(true);
$mail ->Username = "xxxxx";
$mail ->Password = "xxxxx";
$mail ->SetFrom("xxxxx");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
?>
Related
I've been trying to make a small E-mail function, so it's possible to send an E-mail to my Outlook from my website. But I'm running into some problems..
Do I have to change anything in my php.ini (xampp)? and username and password should be my outlook usn/pass right?
When I run this .php it says: echo "Mail Not Sent";
Can't really see what I'm doing wrong.
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.office365.com";
$mail ->Port = 587; // or 587
$mail ->IsHTML(true);
$mail ->Username = "mhoegstrup#company.com";
$mail ->Password = "XXXX";
$mail ->SetFrom("mhoegstrup#company.com");
$mail ->Subject = "Test";
$mail ->Body = "HEJJ";
$mail ->AddAddress("mhoegstrup#company.com");
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
The file PHPMailer is from: https://drive.google.com/file/d/0BzlVPBUP5IM8dmpDZ2tEZjdRaEU/view
Thanks for the help!
I checked documentation and settings of outlook service:
I realized you just need to set SMTPSecure to PHPMailer::ENCRYPTION_STARTTLS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
This question already has answers here:
Phpmailer error "Could not instantiate mail function"
(18 answers)
Closed 3 years ago.
I have an issue in sending mail from PHPMailer. When I try to send a message, I get an error message which is
Message could not be sent. Mailer Error:Could not instantiate mail function.
My SMTP is correct, I can't find the problem. Can anyone help me find the problem? Thanks
<?php
require "autoload.php";
if(isset($_POST["submit"])){
$mail = new PHPMailer(true);
$sender = "demo#gmail.com";
//SMTP
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = demo#gmail.com; // SMTP username
$mail->Password = '1234567'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS
$mail->Port = 587; // TCP port to connect
$mail->From = "demo#gmail.com";
$mail->FromName = 'Mailer';
$mail->setFrom(demo#gmail.com, 'Mailer');
$mail->addAddress($_POST["receiver"]); // Name is optional
$mail->Subject = $_POST["subject"];
$mail->Body = $_POST["message"];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
?>
You have set various SMTP-related properties, but you have not told PHPMailer to use SMTP!
Add this line:
$mail->isSMTP();
You're also enabling exceptions (passing true to the constructor), but have not wrapped your code in a try/catch block. See the examples provided with PHPMailer for how to deal with that.
please recheck your configuration like , user/password, PORT number
Connect to smtp.gmail.com on port 465, if you're using SSL. Else use 587.
Also make sure less secure app is turn on
https://support.google.com/accounts/answer/6010255?hl=en
This question already has answers here:
SMTP connect() failed PHPmailer - PHP
(17 answers)
Closed 4 years ago.
I'm a beginner in php so I had written code for testing which will send an email using php.
I'm using "PHPMailer-5.2.27" to sent email with SMTP on php, but when I run the code the email not sent. I don't know what is the problem. Can anyone help me out!
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "xxxxxxxx";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Subject = "test mail";
$mail->Body = "just a test";
$mail->setFrom('example#gmail.com','aaaa');
$mail->addAddress('example#gmail.com');
if ($mail->send())
echo "mail is sent";
else
echo "something wrong ";
?>
Assuming you have allowed your Gmail account to authorize the server from where you are sending an email.
use $mail->ErrorInfo; in order to debug your issue, this will clarify what is the actual failure reason for sending an email you can refer the below code I have shared.
<?php
require "PHPMailer/PHPMailerAutoload.php";
echo !extension_loaded('openssl')?"Not Available":"Available"; //check openssl is available or not
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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; // or 587
$mail->IsHTML(true);
$mail->Username = "mygmailaccount#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("toaddress#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
I can actually send the emails but I want to change the email from name. When I send emails, it comes into the receiver mailbox with my mail id. I want to change that to some other names. Kindly help me to do that. This is my code
<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; // or 587
$mail ->IsHTML(true);
$mail ->Username = "dkdev006#gmail.com";
$mail ->Password = "password";
$mail ->SetFrom("Kreatz.in");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
Look at the docs on this method.
You have $mail ->SetFrom("Kreatz.in");, which is neither a "nice" name nor an email address, so I don't know what you're trying to do there. You probably want to do this:
$mail ->setFrom('dkdev006#gmail.com', 'Kreatz.in');
Bear in mind that you're using gmail to send through, so you are not allowed to set arbitrary from addresses, though you can create fixed aliases in gmail prefs.
You're also using an old version of PHPMailer, and have based your code on an obsolete example, so get the latest version.
I am trying to send an email to user and admin using php-mailer.But when I send the mail, the user Acknowledgement mail is also getting sent to the admin. The e mails getting sent are in proper format. What is the issue here?
My Code is Here:
$name = "User Name";
$email = "user#gmail.com";
$mobile = 'User Phone No.';
$body = "<div><div>Name: <b>$name</b></div> <div>Email: <b>$email</b></div> <div>Mobile: <b>$mobile</b></div></div>";
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail -> isSMTP();
function sendEmail($mail, $from, $password, $to, $body, $subject) {
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail -> SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail -> Debugoutput = 'html';
//Set the hostname of the mail server
$mail -> Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail -> Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail -> SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail -> SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail -> Username = $from;
//Password to use for SMTP authentication
$mail -> Password = $password;
//Set who the message is to be sent from
$mail -> setFrom($from, $from);
//Set who the message is to be sent to
$mail -> addAddress($to, $to);
//Set the subject line
$mail -> Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail -> msgHTML($body);
//Replace the plain text body with one created manually
$mail -> AltBody = 'This is a plain-text message body';
$sucess = $mail -> send();
// //send the message, check for errors
// if (!$sucess) {
// echo "Mailer Error: " . $mail -> ErrorInfo;
// } else {
// echo "Message sent!";
// }
}
$from = "noreplyadmin#gmail.com";
$maiAdmin = "admin#gmail.com";
$password = "password";
$subject = "Enquiry";
// Send Mail to admin
sendEmail($mail, $from, $password, $maiAdmin, $body, $subject);
// Send Mail to User
$userMessage = "We Received your request. Our representative will contact you soon.";
sendEmail($mail, $from, $password, $email, $userMessage, 'Acknowlwdgement');
You are using the same instance and have not cleared the previous out of the PHPMailer $mail instance. You can either clear the old data out of the PHPMailer Instance or do this:
$adminmail = new PHPMailer();
$adminmail -> isSMTP();
$usermail = new PHPMailer();
$usermail -> isSMTP();
sendEmail($adminmail, $from, $password, $maiAdmin, $body, $subject);
$userMessage = "We Received your request. Our representative will contact you soon.";
sendEmail($usermail, $from, $password, $email, $userMessage, 'Acknowlwdgement');
Whatever floats your boat I suppose.