PHPmailer Fatal Error - php

Hi guys i'm trying to use a php mailer however I keep getting issues for example in the sampler my emails simply won't send. So I changed to this new method and when testing i'm getting this error: Fatal error: Class 'SMTP' not found in /home3/hutch/public_html/Murphy/class.phpmailer.php on line 1325 anyone know why this is. I tried chanign the require to ("PHPMailerAutoload.php"); Which still didn't work still got the same error. I got both class.phpmailer.php and PHPMailerAutoload.php from the Github hosted documentation so I'm sure they are up to date. Any ideas?
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.sulmaxmarketing.com"; // SMTP server
$mail->From = "info#sulmaxmarketing.com";
$mail->AddAddress("sulmaxcp#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
?>

You are sending email using SMTP, so you need to include the SMTP class file:
require("class.smtp.php");

Related

$mail->send() in PHPMailer is returning true but I didn't receive mail

I'm using PHPMailer to send emails from my website but $mail->send() is returning true and mail is not sending. No error is reporting in my error log. I hosted my site in Bigrock. I didn't find any errors in my code.
<?php
if(isset($_POST['submit']))
{
require 'class.smtp.php';
require 'PHPMailerAutoload.php';
ini_set('SMTP','localhost' );
ini_set('sendmail_from', 'exmaple#gmail.com');
$fromrec=$_POST['from'];
$from="example#gmail.com";
$subject=$_POST['sf'];
$message=$_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->setFrom($from, 'Rahul');
$mail->addAddress("example1#gmail.com");
$mail->Subject = $subject;
$mail->Body = "From:".$fromrec."".$message;
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else if($mail->send()) {
echo 'Message has been sent.';
echo $mail->ErrorInfo;
}
else
{
echo 'Mailer error: ' . $mail->ErrorInfo;
}
}
?>
On this issue, I have consulted Bigrock customer care and I made a chat with them. It's simple in the above code the from address email id must be domain specific and to address would be anything. After changing the email id to domain specific and Host to mail.example.com. My problem has been solved. If anyone got the same problem please try this.

PHP Fatal error: Class 'SMTP' not found in /home/screcafb/public_html/class.phpmailer.php on line 1520

I am getting the internal server error when I use PHP mailer for sending emails from web page/ I didn't find any solution for that and I don't know how to do configuration of mail in Bigrock server to make PHP mailer work.
Here is the code.
<?php
if(isset($_POST['submit']))
{
require 'PHPMailerAutoload.php';
ini_set('SMTP','localhost' );
ini_set('sendmail_from', 'example#example.com');
$to="example1#example.com";
$fromrec=$_POST['from'];
$from="example#example.com";
$subject=$_POST['sf'];
$message=$_POST['message'];
$mail->isSMTP();
$mail = new PHPMailer;
$mail->setFrom($from, 'test');
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = "From:".$fromrec."".$message;
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
}
?>
The error in the log is:
[30-May-2017 19:08:10 Etc/GMT] PHP Fatal error: Class 'SMTP' not found in /home/screcafb/public_html/class.phpmailer.php on line 1520
You have the call
$mail->isSMTP();
before you've assigned a value to the variable $mail. You need to move that after
$mail = new PHPMailer;

Error in sending SMTP mail

Try to send mail from window server using SMTP.
and i get this error
Fatal error: Class 'SMTP' not found in...
and when i use PHPmailerAutoload.php only then it gives
Fatal error: Call to undefined method SMTP::setDebugLevel() in...
My code is
error_reporting(E_ALL);
ini_set('display_errors','1');
require_once('class.phpmailer.php');
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "mail.host.com.au";
$mail->Port = 25;
$mail->Username = "myusername";
$mail->Password = "mypassword";
$mail->SetFrom('info#company.com.au', 'First Last');
$mail->AddReplyTo("info#company.com.au","First Last");
$mail->Subject = "PHPMailer Test Subject";
$body = "test";
$mail->MsgHTML($body);
$address = "myemail#gmail.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Please provide any suggestion.
i had the same problem doing this.. and i resolved it..
Open your PHPMailer and in that class.phpmailer.php and in that add this line at the starting in the php block: require_once('class.smtp.php');
It'll surely work.. or you can download that two files from this link:
https://github.com/abhishekpanjabi/e-Legal.git
Download phpmailer it has only two requird files and replace it with your phpmailer's files.. it'll work I've uploded image showing code.

Can not send mail from external SMTP on heroku?

I used the following code in my app to send a mail from my heroku app
<?php
require("PHPMailer-master/class.phpmailer.php");
require("PHPMailer-master/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->From = "suneetha.itham#gmail.com";
$mail->AddAddress("suneetha#yantranet.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}else {
echo 'Message has been sent.';
}
?>
But, my app is showing up
"Message was not sent.Mailer error: The following From address failed: suneetha.itham#gmail.com : MAIL FROM command failed,530,5.7.0 Must issue a STARTTLS command first. h20sm18987465qen.5 - gsmtp" \n
Can any one help me to solve this problem.Thanks.
I think this more a issue with your smtp config's See this answer: https://stackoverflow.com/a/16048485/959041
Does your code work on your local machine?

PHPmailer duplicate email issue - conditional statement with $mail->Send()

I came across a bizarre issue with PHPmailer (version 5.1) that I'm trying to workaround. I've seen quite a bit of good feedback on here, so I thought I would give it a try. I've found that when I attempt to create a customized confirmation message with a conditional statement based on $mail->send(), I receive duplicate emails. I can duplicate it with the generic testemail.php script that comes with the PHPMailer download. Here's the code:
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.domain.com"; // SMTP server
$mail->Username = "username"; // SMTP server username
$mail->Password = "password"; // SMTP server password
$mail->IsSendmail();
$mail->From = "example_from#domain.com";
$mail->FromName = "First Last";
$to = "example#domain.com";
$mail->AddAddress($to);
$mail->Subject = "PHP Mailer test";
$message = "This is a test. \n";
$mail->Body = $message;
$mail->Send();
if ($mail->Send()) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
The above code echoes the "Message has been sent" confirmation, but then sends two emails. If I comment out the $mail->send() line, I still receive the "message has been sent" confirmation and only get one message. If I remove the conditional statement and leave the $mail->send() line commented out, no email is sent.
Why does adding a conditional statement cause an email to be sent without calling the $mail->send() method?What is the proper way of adding a customized confirmation message?
When you put $mail->Send() in your conditional, you're actually calling it again, sending another message, and checking if that second message was sent.
If you just keep
if ($mail->Send()) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
and get rid of the original, unconditional Send call, you should be fine.
Alternatively, if it's clearer for you or if you need to do some processing elsewhere that depends on whether the message was successfully sent, you could do the essentially equivalent:
$status = $mail->Send();
if ($status) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}

Categories