I have read similar threads but this problem is different. Problem is that 100% same code with same class is working on another page. But it is not working on index page for some odd reason. Here is error I get:
The only difference is that the working file is located in subdirectory on root that is /xyz but the index file is located in root that is / but the action to the form points to file in sub directory that is /xyz/file.php so I don't think that could be a problem.
PHP Catchable fatal error: Object of class PHPMailer could not be converted to string in /home4/elliot/public_html/web.com/class.phpmailer.php on line 764
Here is what PHP Mailer Shows on line 764:
$address = trim($address);
Here is What working code looks like:
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "removed";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "removed";
$mail->Password = "removed";
//Set who the message is to be sent from
$mail->setFrom('xx#xx.com', 'John Doe');
$mail->addReplyTo('xx#xx.com', 'John Doe');
//Set who the message is to be sent to
$mail->addAddress($email,$full);
$mail->Subject = 'Subject';
$mail->Body = $body;
$mail->IsHTML(true);
$mail->send();
Here is what non working code looks like:
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "removed";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "removed";
$mail->Password = "removed";
//Set who the message is to be sent from
$mail->setFrom('xx#xx.com', 'John Doe');
$mail->addReplyTo('xx#xx.com', 'John Doe');
//Set who the message is to be sent to
$mail->addAddress($email,$full);
$mail->Subject = 'Subject';
$mail->Body = $body;
$mail->IsHTML(true);
$mail->send();
I got it. IT was such a stupid error. I was using $mail variable for both object and also email address.
Related
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');
Thanks in advance.
Below is code from PHPmailer (https://github.com/Synchro/PHPMailer) which is giving me a few problems. It works along side this PHP sign-up (http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html). I know it works other then the email because the table in the database does recieve the values. I can manually update the table and and allow myself to log-in. It does send out a Error 500 page.
function send_mail($email,$message,$subject)
{
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->AddAddress($email);
$mail->Username = "EMAIL#gmail.com";
$mail->Password = "PASSWORD";
$mail->SetFrom('robert.m.smith112#gmail.com','Coding Cage');
$mail->AddReplyTo("robert.m.smith112#gmail.com","Coding Cage");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
}
I am trying to build a mail function with php, but it's justing showing "Invalid address:" after execute. Pleas help.
Below is my code:
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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 = 'myemail#gmail.com';
$mail->Password = 'mypassword';
$mail->From = "myemail#gmail.com";
$mail->FromName = "Web Site";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addAddress('myfriend#gmail.com');
$mail->AddReplyTo('myfriend#gmail.com');
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
Try This
Please write the below line.
$mail->CharSet = "UTF-8"; // To support special characters in SMTP mail
//$mail->SMTPDebug = 2; Comment this line of code
I hope this will help you. Good Luck
<?php
require_once('../class.phpmailer.php');
//include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
iconv_set_encoding("internal_encoding", "UTF-8");
$mail = new PHPMailer();
$mail->CharSet = "utf8";
/*
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
*/
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "mail.app-cpr.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 = 25; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxxxx#gmail.com"; // GMAIL username
$mail->Password = "xxxxxxxxxxx"; // GMAIL password
$mail->SetFrom('xxxxxxx#gmail.com', 'First Last');
$mail->AddReplyTo("xxxxxxx#gmail.com","First Last");
$mail->Subject = "ทดสอบ";
/*
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
*/
$mail->MsgHTML("ทดสอบ");
$address = "xxxxxxx#gmail.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
The email sending is ok but have a problems with the header.
Subject : 'ทดสอบ'
I will try with
- php mail special characters utf8
- use => $mail->Subject = "=?UTF-8?B?".base64_encode($subject)."?=";
But it does not work for me. How can I know what is the header coding and solve this to be right in my Thai langauge?
Use
$mail->CharSet = 'UTF-8';
instead of
$mail->CharSet = "utf8";
I'm trying to configure email by using phpmailer and smtp but Authentication error appears.
Code below
include_once("phpmailer.php");
$mail = new PHPMailer();
$tarih = date("d.m.Y - H:i:s");
$mail->IsSMTP();
$mail->Host = "mail.golcukdh.gov.tr";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->IsHTML(true);
$mail->From = "email";
$mail->AddAddress("email");
$mail->Subject = "subject";
$mail->Body = "Body Part";
$mail->Send()
?>
I tried to configure this by using asp.net with these authentication information and it was successfull. But I want to use php, what is wrong ?