Code: -
$mail = new PHPMailer();
$body="<b>This mail is sent using PHP Mailer</b>";#HTML tags can be included
$mail->IsSMTP();
$mail->SMTPAuth = true; #enable SMTP authentication
$mail->SMTPSecure = "tls"; #sets the prefix to the server
$mail->Host = "smtp.gmail.com"; #sets GMAIL as the SMTP server
$mail->Port = 587; #set the SMTP port
$mail->Username = "morelifelondon#gmail.com"; #your gmail username
$mail->Password = "***********"; #Your gmail password
$mail->From = $email;
$mail->FromName = $name ;
$mail->Subject = "Enquiry";
$mail->Body = $messages;
$mail->AddAddress("morelifelondon#gmail.com","contact");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Mail has Been Sent.';
}
}
I want that morelifelondon#gmail.com is replaced by abhishek#gmail.com. Is this possible ?
$mail->AddAddress("abhishek#gmail.com","contact");
or use
$mail->AddCC("abhishek#gmail.com","contact");
Related
I am trying to send messages from my website specialeducationnotes.co.in but not able to send the messages.
<?php
if(isset($_POST['query-submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
// $mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail#gmail.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
$from = $_POST['email'];
$subject = $_POST['subject'];
$mail->From = $from;
$mail->FromName = $_POST['name'];
$mail->addAddress('specialeducationnotes1#gmail.com'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = '<h2 style="text-align: center;"s>Name: '.$_POST['name'].'<br>Email: '.$_POST['email'].'<br>Message: '.$_POST['query'].'</h2>';
$mail->AltBody = 'Hello! Hola! Namaste!';
if(!$mail->send()) {
//echo 'Message could not be sent.';
echo "<script>alert(' Your message could not be sent!');</script>";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo 'Message has been sent';
echo "<script>alert(' Your message is sent!');</script>";
echo "<script>document.location.href='index.php'</script>";
}
}
?>
I just get a blank page with no error message or any text and email is also not sent. Can you tell what's wrong with my code?
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 3 years ago.
I am using PHPMAILER and I am fairly new in it.
I have used the following code but for some reason the email is being sent to spam. Please have a look at the code and tell me what I need to fix. (I am new to using email
<?php
require 'php-mailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isMail(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'kfhcareer#gmail.com.com'; // SMTP username
$mail->Password = 'password12345'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('kfhcareer#gmail.com', 'KFH Bahrain');
$mail->addAddress('kfhcareer#gmail.com', 'Joe User'); // Add a recipient
$mail->AddReplyTo( 'mailer#blah.com', 'Contact BLah' );
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'KFH house bahrain';
$mail->Body = 'This is tthe message <b>in bold!</b>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
require("PHPMailer/class.phpmailer.php");
$sender = "sender#gmail.com"; //gmail of the sender
$password = "senderpassword"; //the password
$receiver = "receiver#gmail.com"; // the receiver email
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->From = $sender;
$mail->FromName = $sender;
$mail->Host = "smtp.gmail.com"; // specif smtp server
$mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected 465
$mail->SMTPAuth = true;
$mail->Username = $sender; // SMTP username
$mail->Password = $password; // SMTP password
$mail->AddAddress($receiver, $receiver); //replace myname and mypassword to yours
$mail->AddReplyTo($receiver, $receiver);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "This is Subject";
$mail->Body = "This is Body";
if(!$mail->Send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I am new at PHP. I am using PHPMailer to send emails but unable to do so. I tried configuring it for gmail and it worked But not working when tried to send msg from remote host and for the given domain.
Here is the code.
<?php
require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file.
$mail = new PHPMailer();
//$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "175.000.000.000"; //Sample Host
$mail->SMTPDebug = 1;
$mail->Port = "25"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
$mail->Username = "maaz#mcbah.com";
$mail->Password = "password";
$mail->From = "maaz#mcbah.com";
$mail->FromName = "Maaz Khan";
$mail->AddAddress("mcbah.all#mcbah.com", "all");
$mail->AddReplyTo("fundprices#mcbah.com", "Fund");
$mail->Subject = "Hi!";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';
exit;
} else {
echo 'Message has been sent.';
}
This code may help you
$mail->Host = "smtpout.secureserver.net";
Your host name should be like mydomain.com
$mail->Port = 465;
I use this code to send an email:
When I open the mail.php file in my browser. Nothing will send. The browser will load a blank page with no message displayed saying the email was sent. I have been searching on StackOverflow and other websites for a solution. Can someone help me?
<?php
require_once("phpmailer\class.phpmailer.php");
// path to the PHPMailer class.
require_once("phpmailer\PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = "25";
// 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
// Uncomment this line if you want to use SSL.
$mail->Username = "emailer#my.domain";
$mail->Password = "password";
$mail->From = "example#gmail.com";
$mail->FromName = "Susan Sender";
$mail->AddAddress("rachel#my.domain", "Rachel Recipient");
//$mail->AddReplyTo("Your Reply-to Address", "Sender's Name");
$mail->Subject = "Hi!";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
}
else {
echo 'Message has been sent.';
}
?>
i want to send an email from localhost to gmail, but it says "SMTP connect() failed"
here is my code. I've also tried to change configuration php.ini and sendmail.ini but no luck.
Thank you.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'asd#gmail.com';
$mail->Password = 'password';
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('asd#gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Email'
$mail->Body = "This is body";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Try out the following :
Ensure that the PHPMailer library is included in the code.
Ensure that you are internet connection from localhost is not inhibited by any proxy.
Happy Coding :)
check the line $mail->Subject = 'Email' for a missing ;