I'm frustrated to fix this.
One time I made it work. The next day, an error annoys me:
Warning: Attempt to assign property of non-object in C:\XAMPP\htdocs\HAF\includes\sendmail.php on line 356
Help me fix this :(
Here's my code:
sendmail.php
class SendMail {
function notification($recipient, $name, $subject, $message) {
global $email;
$email->Host = "smtp.gmail.com";
$email->SMTPAuth = true;
$email->Username = "******#gmail.com";
$email->Password = "**********";
$email->SMTPSecure = "tls";
$email->Port = 465;
$email->setFrom('admin#gmail.com', 'My WebApp');
$email->addAddress($recipient);
$email->isHTML(true);
$email->Subject = $subject;
$email->Body = $message;
if(!$email->send()) {
return false;
} else {
return true;
}
}
}
index.php
$email = "jaydenjames#gmail.com";
$name = "Jayden James";
$message = "Welcome {$name}!";
$SendMail->notification($email, $name, 'Welcome guest!', $message);
update answer with gmail configuration....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'MyUsername#gmail.com';
$mail->Password = 'valid password';
$mail->SMTPAuth = true;
$mail->From = 'MyUsername#gmail.com';
$mail->FromName = 'Mohammad Masoudian';
$mail->AddAddress('anotherValidGmail#gmail.com');
$mail->AddReplyTo('phoenixd110#gmail.com', 'Information');
$mail->IsHTML(true);
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
Related
is my code correct or give some suggestion for sitemailxchange host and with port number..? i have check most of combination .
Thanks in advance.
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.sitemailxchange.gate.com";
$mail->Port = 587;
$mail->Username = "yourmail#domain.com";
$mail->Password = "password";
$mail->SetFrom('yourmail#domain.com');
$mail->AddReplyTo("yourmail#domain.com");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, viewer!";
$mail->MsgHTML($body);
$address = "yourmail#domain.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I want to create a loop for my mail system that uses the format
stan.smith#americandadcia.fx, Stan Smith
So that I can pass it through my function
function SendEmail($to,$fromName, $subject, $message)
{
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = smtp_host;
$mail->Port = smtp_port;
$mail->SMTPSecure = smtp_protocol;
$mail->SMTPAuth = true;
$mail->Username = smtp_user;
$mail->Password = smtp_pass;
$mail->setFrom(smtp_user, $fromName);
$mail->addReplyTo(smtp_user, $fromName);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML($message);
$mail->send();
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
This code is to go through a loop, so say you have
Stan Smith, Roger Smith and Francine Smith the form input would have
stan.smith#americandad.fx, Stan Smith; roger.smith#amongyou.ufo, Roger Smith; francine.smith#desperatehousewives.fox, Francine Smith
The addresses would then be passed into my functions file and ran through the function to send the email
$mail = new MailSystem();
$emails=$_POST['emailTo'];
$email=explode(";",$emails);
foreach($email as $address) {
echo $mail->SendEmail($address, SITE_NAME." Newsletter", $_POST['emailSubject'], $_POST['emailBody']);
}
My Problem is that when the email attempts to send it's going to try to run $mail->addAddress($address) and I get the response that it's an invalid address. I can go in and manually set the addAddress with my email", "My name" but when it goes through this way it resolves to invalid address.
On the addAddress() you have to split the receiver name and address. Your function should look like the following:
function SendEmail($to,$fromName, $subject, $message)
{
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = smtp_host;
$mail->Port = smtp_port;
$mail->SMTPSecure = smtp_protocol;
$mail->SMTPAuth = true;
$mail->Username = smtp_user;
$mail->Password = smtp_pass;
$mail->setFrom(smtp_user, $fromName);
$mail->addReplyTo(smtp_user, $fromName);
//split the to on , to get mail address and receiver name.
$address = explode(',', $to);
//check if the name is available.
if (!isset($address[1])) {
$mail->addAddress($address[0]);
} else {
$mail->addAddress($address[0], $address[1]);
}
$mail->Subject = $subject;
$mail->msgHTML($message);
//remove the following line because duplicate sending!!!
//$mail->send();
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
Iam using PHP mailer to send an Email the message sent but email body is Empty
here is my code
foreach($results as $result)
{
$email = $result['email'];
$body = 'Hello'.$result['username'].' we remind you to return the book to library after' .$result['days'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.myhost.com;';
$mail->SMTPAuth = true;
$mail->Username = 'send#myhost.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = 'send#myhost.com';
$mail->FromName ='Bookstore';
$mail->addAddress($email, 'username');
$mail->Subject = 'Book returned Time';
$mail->Body = $body;
$mail->IsHTML(true);
if(!$mail->send()) {
echo 'Message could not be sent.';
//echo 'Mailer Error: ' . $mail->ErrorInfo; return $user ;
} else {
echo 'done';
}
}
$msg = 'God Bless You';
$subj = 'Ryan D\'souza Photgraphy Invoice';
$to = $_POST['email'];
$from = 'emailaddres';
$name = $_POST['client'];
smtpmailer($to,$from, $name ,$subj, $msg);
function smtpmailer($to, $from, $from_name = 'Ryan D\'souza Photgraphy', $subject, $body)
{
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.sendgrid.net';
$mail->Port = 465;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->IsHTML(true);
$mail->From="emailaddres";
$mail->FromName="Ryan D'souza Photgraphy";
$mail->Sender=$from; // indicates ReturnPath header
$mail->AddReplyTo($from, $from_name); // indicates ReplyTo headers
$mail->AddCC('cc#site.com.com', 'CC: to site.com');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAttachment('pdfs/'.$_POST['client'].'.pdf');
$mail->AddAddress($to);
$mail->AddAddress("emailaddres");
if(!$mail->Send())
{
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
}
else
{
$error = 'Message sent!';
return true;
}
}
I'm using PHP mailer to attach a file and send mail. the code works on local system but when I upload it on the server that time it gives me Internal server error. I tried commenting and print each line of the code and found out that i get at $mail->Send().
I have used PHPMailer for SMTP and there is problem in sending mail with error "Mailer Error: The following From address failed: no-reply#mydomain.org.uk"
My code is as follows:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "localhost;"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = $email_address;
$mail->FromName = $email_address;
$mail->AddAddress($arrStudent[0]["email"]);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject";
$theData = str_replace("\n", "<BR>", $stuff);
$mail->Body = $theData; // "This is the <b>HTML body</b>";
$mail->AltBody = $stuff;
if (!$mail->Send()) {
$sent = 0;
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
i researched everything and when i debug inside class.smtp.php i found error the function "get_lines()" is returning error value "550 Authentication failed"
The code was working fine previously, i am wondering how this problem came suddenly.
Desperate for some help.
Thanks,
Biplab
public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
require_once('mailer.class.php');
$mailer = new PHPMailer();
//do we use SMTP?
if ( USE_SMTP ) {
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->Host = SMTP_HOST;
$mailer->Port = SMTP_PORT;
$mailer->Password = '';
$mailer->Username = '';
if(USE_SSL)
$mailer->SMTPSecure = "ssl";
}
$mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
$mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );
$mailer->AddAddress($to);
$mailer->Subject = $subject;
//$mailer->WordWrap = 100;
$mailer->IsHTML ( TRUE );
$mailer->MsgHTML($body);
require_once('util.class.php');
$mailer->AltBody = Util::html2text ( $body );
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if ( ! $mailer->Send() ) {
return FALSE;
}
else {
$mailer->ClearAllRecipients ();
$mailer->ClearReplyTos ();
return TRUE;
}
}
I've used like that... SetFrom should be used in place of From... that's your error buddy... :))
try adding belowe line to php.ini
extension=php_openssl.dll
restart and try again
I am using YII's Mailer with PHPMailer, and this works for me:
$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Username = $this->SMTP_USERNAME; // SMTP username
$mail->Password = $this->SMTP_PASSWORD; // SMTP password
$mail->SMTPAuth = true;
$mail->From = $this->fromAddress;
$mail->Host = $this->SMTP_SERVER_ADDRESS;
$mail->FromName = $this->fromName;
$mail->CharSet = 'UTF-8';
$mail->Subject = Yii::t('mailer', $this->subject);
$mail->Body = $this->message;
$mail->AddReplyTo($this->toAddress);
$mail->AddAddress($this->toAddress);
$mail->IsSMTP(true);
$mail->IsHTML(true);
$mail->Send();
Hope that helps?