I'm using php mailer and i cant specify the sender mail , i want to be a variable every one type his email to be here , but it cant be done i must type my email and my password , so anyone know how it can be done
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.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 = "usermail"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->addReply=$_POST['email'] ;
$mail->addAddress=$_POST['email'];
$mail->Subject=$_POST['subject'];
$mail->Body=$_POST['message'] .$_POST['email'];
$mail->Sender=$_POST['email'];
try this code
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // 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 = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
#$mail->Send()
Go through this link -> Own-Email-System-using-SMTP-and-PHPMailer
OR,
Please elaborate your issues so that i can help you properly .
NOTE:If "Less secure app access" is turned off for your Gmail account, you have to turn it on. => Click Here To see . Is it ON or OFF
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer;
//Enable SMTP debug mode
$mail->SMTPDebug = 0;
//set PHPMailer to use SMTP
$mail->isSMTP();
//set host name
$mail->Host = "smtp.gmail.com";
// set this true if SMTP host requires authentication to send mail
$mail->SMTPAuth = true;
//Provide username & password
$mail->Username = "YOUR_GMAIL_EMAIL_ID";
$mail->Password = "YOUR_GMAIL_PASSWORD";
$mail->SMTPSecure = "tls";
$mail->Port = 587;// Enter port number
$mail->ClearReplyTos();
$mail->addReplyTo("YOUR_GMAIL_EMAIL_ID", $_POST['name']); //$_POST['name'] => YOUR_GMAIL_NAME . You Can directly give "YOUR_GMAIL_NAME"
$mail->SetFrom("YOUR_GMAIL_EMAIL_ID", $_POST['name']);
$mail->addAddress($_POST["email"]); //TO WHOM U R SENDING MAIL
//Subject
$mail->isHTML(true);
$mail->Subject =" ".$_POST['subject']." ";
$body = "<html>
<head> </head>
<body>
".$_POST['message']." <br>
</body>
</html>";
$mail->MsgHTML($body);
if(!$mail->send()) {
$error_message = "Mailer Error : ". $mail->ErrorInfo;
echo $error_message;
} else {
echo "Email Sent Successfully";
}
?>
Related
I am trying to send an email using the gmail smtp server as a relay in php. I am programming in webmatrix server and I use PHPMailerAutoload library to send the emails.My operating system is windows 7 64 bit.I already have configured php.ini to use gmail smtp server.When running the code i get the success message but no emails is sent.Could anyone please help me find the problem,thanks.Here is part of my code:
$mail = new PHPMailer(true);
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example"; // GMAIL username
$mail->Password = "password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("example#gmail.com", "name");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
$mail->SMTPDebug = true;
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
Download the wrapper file
PHPMailer, import the file as shown below.
require '../PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example"; // GMAIL username
$mail->Password = "password"; // GMAIL password
}
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("example#gmail.com", "name");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
$mail->SMTPDebug = true;
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}
I am trying to send an email from localhost with PHP. Here is my code:
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = false; // turn on SMTP authentication
$mail->Username = "TTTTTT#gmail.com"; // SMTP username
$mail->Password = ""; // SMTP password
$mail->Port = 25;
$mail->SMTPSecure = '';
$mail->From = $email;
$mail->AddAddress("bradm#inmotiontesting.com", "Brad Markle");
$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;
}
echo "Message has been sent";
?>
When I run this code, it shows, "message has been sent" but it does not actually send the message. What is my problem?
change this code you have:
$mail->Username = "TTTTTT#gmail.com"; // SMTP username
$mail->Password = ""; // SMTP password
$mail->Port = 25;
$mail->SMTPSecure = '';
to this:
$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 = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
In addition to what Lelio Faieta posted, enable less secure apps in gmail
and to prevent your mail going to your spam
change
$mail->From = $email;
to your email and you can put $email in body of your message
i want to send email after user checkout from cart
my controller:
include('js/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server Gmail
$mail->Mailer = "smtp";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 1;
$mail->Username = "my gmail"; //
$mail->Password = "my pass"; // SMTP password
$webmaster_email = "my gmail"; //Reply to this email ID
$email = "recipient gmail"; // Recipients email ID
$name = "John"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Aryono King";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Goeboek I-Mut");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject Test";
$mail->Body = "Test Content"; //HTML Body
if(!$mail->Send()) {echo "Mailer Error: " . $mail->ErrorInfo;}
else {echo "<strong>Email Send</strong>";}
but it show error like this
2015-05-20 21:46:43 SMTP ERROR: Failed to connect to server: (0) 2015-05-20 21:46:43 SMTP connect() failed. Mailer Error: SMTP connect() failed.
what's the problem? i can't solve it, i search everywhere and i can't fint the answer, please someone help me
Take a look at the example here.
While personally, I do it like this:
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.googlemail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $email_mail; // SMTP username
$mail->Password = $email_pass; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
Try to check against yours, like for example: $mail->Host = 'ssl://smtp.googlemail.com';, which supposed to be don't have ssl://.
Two things you need to check before using phpmailer for gmail
need to check whether SMTP port and email + password is correct or not
You need to authenticate from your gmail account for sending email from unsecured sources, means: when first you send an email, google will send you an email asking your permission to allow to forward email from your id, here your required to click allow
One more thing, Port 587 is working perfectly for me, instead of 465
Hi,
there's more...I have seen that antivirus or firewall installed in your computer may block sending emails via localhost as it may considered as spam attacks
use this code...
include 'PHPMailerAutoload.php';
function send_mail($mail_to,$mail_to_fname,$mail_to_lname,$subject,$message)
{ $mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = 'mail.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = " YOUR GMAIL ";
$mail->Password = " YOUR GMAIL PASSWORD";
$mail->setFrom(' YOUR GMAIL ', ' YOUR NAME ');
$mail->addAddress($mail_to,$mail_to_fname . " " . $mail_to_lname);
$mail->Subject = $subject;
$mail->msgHTML($message);
$mail->AltBody = ' ';
if (!$mail->send()){echo "FALSE" . $mail->ErrorInfo;}
else{echo "TRUE";}
}
// How to user
// send_email(" email address where to send "," reciepient first name ","reciepient last name "," subject ", " message as html code ");
you need to do one more step for allowing gmail to send messages...!
(*) accept to allow google to send emails from unsecured apps, that link will be sent to your gmail, after you send first email
I use class.phpmailer.php to send a confirmation email. It works perfectly in my local server, but when I upload it to the server in 000webhost.com it no longer works.
I just discovered mail() is not working anymore either.
Is there something I can do to solve this?
Here is the code of the function I use to send every mail in my system:
code
function correoEnviar($asunto, $mensaje, $mensajeTexto, $email)
{
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxx#yahoo.com.mx'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'xxxx#yahoo.com.mx';
$mail->FromName = 'xxxx';
$mail->addAddress($email); // Name is optional
$mail->addReplyTo('xxxx#yahoo.com.mx', 'Information');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
//$mail->Subject = 'Por favor confirme su correo para obtener el libro El fractal y el =?UTF-8?Q?dise=C3=B1o=C2=A0gr=C3=A1fico?=';
$mail->Subject = $asunto;
$mail->Body = $mensaje;
$mail->AltBody = $mensajeTexto;
if(!$mail->send()) {
return $mail->ErrorInfo;
}
else
return 1;
}
echo correoEnviar($asunto, $mensaje, $mensajeTexto, "recipent#gmail.com");
?>
code
Are you sure you are including the file class.phpmailer.php, your code seems fine.
Paste the server's mailserver log, it will provide a better insight.
Your code is fine, it might be a server issue.
A sample code showing SMTP settings
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn of SMTP authentication
$mail->Username = "YAHOO ACCOUNT"; // SMTP username
$mail->Password = "YAHOO ACCOUNT PASSWORD"; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Host = "YAHOO HOST"; // SMTP host
$mail->Port = 465;
I have the below code and I am getting the following error:
I am using the version PHPMailer_v5.1. I tried another version but it did not work. Any Ideas?
SMTP Error: Could not authenticate
$mail = new PHPMailer(false); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.easyname.eu"; // SMTP server
$mail->Port = 465;
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "info#mydomain.net"; // SMTP account username
$mail->Password = "*****"; // SMTP account password
$mail->AddReplyTo("$fromEmail", "$from");
$mail->AddAddress("$toEmail", "$toName");
$mail->SetFrom("$fromEmail", "$from");
$mail->Subject = "New enquiry to example (SUBJECT:'$subject')";
$mail->AltBody = "$message"; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("$message");
$mail->Send();
if($settings['cc_sender'])
{
$mail = new PHPMailer(false); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.easyname.eu"; // SMTP server
$mail->Port = 465;
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "info#mydomain.net"; // SMTP account username
$mail->Password = "******"; // SMTP account password
$mail->AddReplyTo("no-reply#mydaomain.net", "example Website");
$mail->AddAddress("$fromEmail", "example Enquiry");
$mail->SetFrom("info#mydomain.net", "example Enquiry");
$mail->Subject = "Your enquiry from example (SUBJECT:'$subject')";
$mail->AltBody = "$message"; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("$message");
$mail->Send();
}