hello i would like to send a confirmation email via my website when you create an account. unfortunately I can't get any further, can you help me?
Here is my code:
function send_activation_email($email,$usrnameemail,$code) {
mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "XXX";
$mail->Password = "XXX";
$mail->IsHTML(true);
$mail->AddAddress($email, $usrnameemail);
$mail->SetFrom(mail_from, mail_sender);
$mail->AddReplyTo(mail_from, mail_sender);
$mail->AddCC(mail_from, mail_sender);
$mail->Subject = 'Test Email';
$content = "<b>This is a Test Email sent via Gmail SMTP Server using PHP mailer class. </b><a href='$code'>Click here to activate your account</a>";
$mail->MsgHTML($content);
if(!$mail->Send()) {
echo "Error while sending Email.";
var_dump($mail);
} else {
echo "Email sent successfully";
}
}
Today You cannot use the email password you're using when accessing gmail.com to send emails using SMTP.
You should activate/create App Password. When done you will got a password that you can use for Your PHP Mailer.
its can help You too, if Your App Password has security breach, You can simply delete that App password and recreate new one.
for reference You can access:
https://support.google.com/accounts/answer/185833?hl=en
Related
Instead of using php's mail() function, I've been trying to set up PHPMailer with no success. I put in "echo here" for debugging purposes, and that is all it shows. I do not get any emails, or the sent or error messages. I'm stumped, and after researching it on here may switch to swift mailer. I'd really like to know what I screwed up though.
In my code, address is set to my email, and the username and password are set to a dummy account I made.
<?php
include('class.phpmailer.php');
$mail = new PHPMailer();
$address = "test#gmail.com";
$body = "test email";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$mail->SetFrom('name#yourdomain.com', 'Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);
echo "Here";
if($mail->Send()) {
echo "Message sent!";
}
else {
echo "Mailer Error: " ; $mail->ErrorInfo;
}
?>
As you are using Gmail I think you must make sure the gmail account has the insecure application auth activated
Need help!!!
I am using php mailer in my current project. It works successfully, after sending a mail successfully to the other end it says the mail comes from the smtp server account not from the $from what i use here-
$to ="muradautorun#gmail.com";
$from ="tanvir_cse0906#yahoo.com";
My smtp server code here..
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "muradautorun";
$mail->Password = ""; //my passsword here
Here is my complete code-
$to ="muradautorun#gmail.com";
$from ="tanvir_cse0906#yahoo.com";
$from_name="S.M. Murad Hasan Tanvir";
$subject="A sending mail code";
$body ="This is a sending email code, the file attach here is about the coding.";
//here i use gmail as a smtp server
$mail = new PHPMailer(); // create a new object
$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 = "muradautorun";
$mail->Password = ""; //my passsword here
$mail->SetFrom($from, $from_name);
$mail->addAttachment('emailSend.php'); // Add attachment(just the file url)
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo 'Mail error: '.$mail->ErrorInfo;
}
else {
echo 'Message sent!';
}
?>
Where i doing wrong i can't find out please help me...
Thanks in advance.
You need to allow sending mail as "tanvir_cse0906#yahoo.com" on your "muradautorun" gmail account first.
You can do this by following the following steps:
Login with "muradautorun"
Click the gear in the top right and choose "Settings"
Click on the "Accounts and Import" tab
Click on link "Add another email address you own" in the "Send mail as" section, and follow the instructions.
I want to send a confirmation mail to an user who is trying to register. Iam using PHP Mailer for sending mails. Here is my code:
require_once("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "root";// SMTP username
$mail->Password = "";// SMTP password
$mail->SetLanguage("en","PHPMailer/language");
//compose mail
$mail->From = "admin#localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin#localhost.com", "Cinema Admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/user.login_plugin/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
When I execute the file,it says
Message was not sent
Mailer Error: SMTP connect() failed.
Could anyone suggest me for sending mails from localhost to the registered user's emailid.
I had searched with few titles regarding "ending emails" in stack overflow, but couldn't find any solution from any posts.
Thank You in advance
Could you try remove the smtp part? From your comment , you do not have mail server setup.
$mail = new PHPMailer();
$mail->SetLanguage("en","PHPMailer/language"); // remove smtp things
You must need a SMTP details in order to send an email using SMTP, For example if you want to setup SMTP using gmail,
$mail->IsSMTP(); // telling the class to use SMTP
$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
If you don't want use SMTP, you can called default mail function
$mail->IsMail(); //Sets Mailer to send message using PHP mail() function.
I have been trying to send PHP emails via gmail account having non gmail domain but the email address is registered at gmail.com. The emails are not going via this account but when I give an account having #gmail.com, then the email is transmitted but it is not sending to non gmail email addresses. The code I have been using is php mailer code.
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$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->IsHTML(true);
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
Can someone suggest what am I doing wrong.
Try use host:
$host = "ssl://smtp.gmail.com";
You should register the application who sends the mail in your gmail account:
Start session in your browser in the gmail account.
In the same browser with the session opened, go to https://accounts.google.com/b/0/DisplayUnlockCaptcha
Send a mail executing your php in the desired server you want to enable.
I am trying to send user a activation link through mail by using my gmail account. how do i set it up.How do Send email using Gmail? Where do I put the password?.
Is it to ancient or should I go for object oriented method.
// secure the password
$passWord = sha1($passWord);
$repeatPass = sha1($repeatPass);
// generate random number
$random =rand(1200345670,9999999999);
//send activation email
$to = $email;
$subject = "Activate your account";
$headers = "From: ti.asif#gmail.com";
$server = "smtp.gmail.com";
$body = "Hello $username,\n\n You registered and need to activate your account. Click the link below or paste it into the URL bar of your browser\n\nhttp://phpacademy.info/tutorials/emailactivation/activate.php?id=$lastid&code=$code\n\nThanks!";
ini_set("SMTP",$server);
if (!mail($to,$subject,$body,$headers))
echo "We couldn't sign you up at this time. Please try again later.";
else
{
// register the user
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$userName','$passWord','$fullName','$date','$random','0','$email')
");
$lastid = mysql_insert_id();
die ("You have been registered. <a href='login.php'>Click here</a> to return to the login page.");
echo "Successfully Registered";
}
Download phpmailer and try the following code
<?php
$mail = new PHPMailer();
$mail->IsSMTP();
//GMAIL config
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "gmailusername"; // GMAIL username
$mail->Password = "gmailpassword"; // GMAIL password
//End Gmail
$mail->From = "from#email.com";
$mail->FromName = "you name";
$mail->Subject = "some subject";
$mail->MsgHTML("the message");
//$mail->AddReplyTo("reply#email.com","reply name");//they answer here, optional
$mail->AddAddress("address#to.com","name to");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {//to see if we return a message or a value bolean
echo "Mailer Error: " . $mail->ErrorInfo;
} else echo "Message sent!";
the mail builtin is not very suitable for this, it supports only simple setups.
have a look at pear mail, the examples show you how to send using smtp auth.