I am trying to send mail from PHP using my yahoo credentials.
$Mbody=$Mbody."<body>";
$Mbody=$Mbody."<table border=0>";
$Mbody=$Mbody."<tr>";
$Mbody=$Mbody."<td>Hi,</td>";
$Mbody=$Mbody."</tr>";
$Mbody=$Mbody."<tr>";
$Mbody=$Mbody."<td>New Mail for testing.</td>";
$Mbody=$Mbody."</tr>";
$Mbody=$Mbody."<tr>";
$Mbody=$Mbody."<td><a href=http://www.google.com >Verify Account</a></td>";
$Mbody=$Mbody."</tr>";
$Mbody=$Mbody."</table>";
$Mbody=$Mbody."</body>";
$Mbody=$Mbody."</html>";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->Host = "plus.smtp.mail.yahoo.com";
$mail->Port = 465; // set the SMTP port
$mail->Username = "********";
$mail->Password = "********";
$mail->From = "********";
$mail->FromName = "my Name";
$mail->AddAddress('********');
$mail->Subject = "Subject";
$mail->Body = $Mbody;
When I execute the code, it does send mail to desired recipient, but the body shows all HTML tag in the received mail. What is missing in above code.
Try This
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Subject';
$mail->MsgHTML($Mbody);
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
Please use content-type as HTML
$mail->IsHTML(true); // send as HTML
Related
I am trying two send two mails using PHPMailer and i am getting one mail, But i am not getting the second mail(the user acknowledgement mail). Could some one help me out with this
include_once("mail/class.phpmailer.php");
$mail = new PHPMailer(); // Passing `true` enables exceptions
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
//$mail->isSMTP(); //Set mailer to use SMTP(for live server remove or comment this line)
$mail->Host = 'mail.****.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '********'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'TSL'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->From = $email_from;
$mail->FromName = $first_name;
$mail->addAddress('********#abc.com'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$txt='You got a mail from :<br>';
$mail->Body =$txt;
$mail->Send();
$mail->ClearAllRecipients();// Remove previous recipients
$mail->ClearAddresses();
$mail->From = "********#abc.com";
$mail->FromName = "Some Name";
$mail->AddAddress("********#abc.com");
$mail->IsHTML(true);
$thank_mesg = "Thank You For Sending Us Mail, We Will Reach You As Soon As Possible";
$mail->Subject = "Enquiry From xxxxxxx";
$mail->Body = $thank_mesg;
$mail->send();
Here is a some advice to fix your code:
first, you can use two instance of phpMailer class, Like:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer(true);
$mail->isHTML();
$mail->IsSMTP();
$mail->setFrom('admin#mysite.com', 'admin site');
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $message1;
$mail->Send();
$mail2 = new PHPMailer(true);
$mail2->isHTML();
$mail2->IsSMTP();
$mail2->setFrom('admin#mysite.com', 'admin site');
$mail2->AddAddress($adminemail);
$mail2->Subject = $subject;
$mail2->Body = $message2;
$mail2->Send();
second, some providers impose restrictions on the number of messages that can be sent within a specific time so use sleep() function to check if it is worked or not.
$txt='You got a mail from :<br>';
$mail->Body =$txt;
$mail->Send();
sleep(10); // <<<--------------add this line - in second;
$mail->ClearAllRecipients();// Remove previous recipients
$mail->ClearAddresses();
$mail->From = "********#abc.com";
$mail->FromName = "Some Name";
$mail->AddAddress("********#abc.com");
$mail->IsHTML(true);
$thank_mesg = "Thank You For Sending Us Mail, We Will Reach You As Soon As Possible";
$mail->Subject = "Enquiry From xxxxxxx";
$mail->Body = $thank_mesg;
$mail->send();
I had an error with the sending of an e-mail with php, because I have an smtp server name call smtp.office365.com, how should I try?
<?php
require "PHPmailer/src/PHPMailer.php";//Am I correctly include thelibraries?
require "PHPmailer/src/smtp.php";
$mail = new PHPMailer(true); >I get an error
$mail->isSMTP();
$mail->Host='smtp.office365.com';
$mail->Port=25;
$mail->SMTPAuth= true;
$mail->Username='username';//What username have I had to type?
$mail->Password='password';//The password is above office365 email?
$mail->SetFrom('sender_email', 'FromEmail');
$mail->addAddress('destination', 'ToEmail');
$mail->IsHTML(true);
$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';
?>
I get an error, because when I try to execute It on a server Linux It won't send the email and It gave me a 'HTTP ERROR 500'
$mail->Host=smtp.office365.com
$mail->Port=587
$mail->Username=XXXXXXX
$mail->Password=XXXXXXX
$mail->Encryption=tls
require "PHPmailer/src/PHPMailer.php";
require "PHPmailer/src/smtp.php";
$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 = 'tls'; // secure transfer enabled REQUIRED for 365
$mail->Host = 'smtp.office365.com';
$mail->Port = 25;
$mail->Username = 'username';
$mail->Password = "password";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress('myemail#gmail.com');
I am having trouble figuring out how to send an email to recipient1 with their information, then an email to recipient2 with their information, recipient3 with their information, and so on, all within the same script.
$date=date("Y-m-d");
$time=date("H:i");
$result=mysql_query("select * from reminder where R_Date='$date' && R_Time='$time'");
date_default_timezone_set( "Asia/Kuala_Lumpur");
$receiver=array();
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // 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 = 'example#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
while($row=mysql_fetch_assoc($result)){
if($row){
$mail->From = 'from#example.com';
$mail->FromName = 'CIMB Clicks';
$mail->addAddress($row['R_Email'], $row['R_ID']); // Add a recipient
$mail->addAddress($row['R_Email']); // Name is optional
$mail->WordWrap = 1000; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$body="Greetings from Clicks!<br><br>".
$row['R_Title'].".<br>".
"This is My Reminder from Clicks regarding ".$row['R_Title'].".<br><br>".
"Thank you & have a good day ahead!<br><br>
$mail->Subject = 'My Reminder from Clicks';
$mail->Body = $body;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
}
}
my Database
R_ID R_Title R_Date R_Time R_Email
1 Top Up 2014/10/15 19:41 email#hotmail.com
2 Transfer 2014/10/15 19:41 email#live.com
Assuming you have an array of E-Mail address you could make a foreach-loop. But your question isnt that detailed.
$recipients = array('peter#anymail.com', 'paul#anymail.com', 'mary#anymail.com');
$content = 'same content';
$subject = 'same subject';
foreach($recipients as $address) {
mail($address, $subject, $content, 'FROM: me#anymail.com');
}
Hello guys i get this error,
Message could not be sent.Mailer Error: The following From address failed: hehe.gmail.com : Called Mail() without being connected.
<?php
require '/PHPMailer_5.2.4/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'hehe#gmail.com'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->Port = 465;
$mail->From = 'hehe#gmail.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('hehe#gmail.com'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$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;
exit;
}
echo 'Message has been sent';
How can i fix it? Thanks!
Have you enabled access to less secure apps from your gmail id??
Please try this
<?php
include "PHPMailer_5.2.4/class.phpmailer.php"; // include the class name
$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 = "gmailusername#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("anyemail#gmail.com");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
?>
Please edit your gmail and password correctly.
You may see the demo on Click here
You need to use TLS, not SSL if you're using going to use gmail. Here is an example below
//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 = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//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 = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//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(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
#ref: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
In my case it was because of virus guard..I disabled it and checked.It worked.
At first; Sorry for my bad english skills. I allready try to improve them.
Here is my Problem. I want to send some mails using phpmailer. But the mailer can't authentificate with every of my mail accounts. the funny thing is two days ago everything worked well.
At least i allready tried the script from the readme file and entered my email information but it still dont work.
I have no idea what to do now and hope that you may help me
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp1.MyServer.de"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mymail#example.com"; // SMTP username
$mail->Password = "mypass"; // SMTP password
$mail->From = "mymail#example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("mymail2#example.com", "test");
$mail->WordWrap = 50; // set word wrap to 50 characters
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
Add below lines and try:
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
or
$mail->SMTPSecure = "tls";
$mail->Port = 587;
Hope this helps