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.
Related
I have this error message. Could you please help me ?
My email.php;
<?php
header('Content-Type: text/html; charset=utf-8');
require 'PHPMailerAutoload.php';
$phpmailer = new PHPMailer;
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.coffeewritingcontent.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'iletisim#coffeewritingcontent.com';
$phpmailer->Password = 'mypassword';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Port = '587';
$phpmailer->From = 'iletisim#coffeewritingcontent.com';
$phpmailer->FromName = $_POST['name'];
$phpmailer->AddReplyTo($_POST['email'], $_POST['name']);
$phpmailer->addAddress('iletisim#coffeewritingcontent.com', 'İletişim Formu');
$phpmailer->isHTML(true);
$phpmailer->Subject = 'İletisim formu mesajı';
$phpmailer->Body = "isim: " . $_POST['name'] . "\r\n\r\nMesaj: " . stripslashes($_POST['message']);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->SMTPDebug = 4;
if(!$phpmailer->send()) {
echo 'Mail gonderilemedi. Hata: ' . $phpmailer->ErrorInfo;
exit;
}
echo 'Mail gonderildi.';
?>
my error;
2016-03-26 21:52:59 Connection: opening to
mail.coffeewritingcontent.com:587, timeout=10, options=array ( )
2016-03-26 21:53:09 SMTP ERROR: Failed to connect to server:
Connection timed out (110) Mail gonderilemedi. Error: Language string
failed to load: connect_host
Plase try this code. I'm using now in a server with GoDaddy and everything going good. Please make sure to require the php library with a require_once instance
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail#mydomain.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('mymail#mydomain.com', 'Name');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->setLanguage('es');
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Welcome!';
$mail->Body = 'This is a messagge test!';
if ( !$mail->send() ) :
echo 'Error while sending mail.';
else :
echo 'The messagge send correctly';
endif;
Did you create an instant of $phpmailer before do all those code? Probably you have to do it. So, if you already do that, please review your file PHPMailerAutoload.php and make sure that you have into your folder all and complety files that phpmailer provide us after the download content. I will show you an example for a correctly code that sends email from phpmailer.
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Please make sure too that you are sending emails from a server already upload. If you are using virtual serves like XAMPP, review this page for enable the smtp configuration: How to configure XAMPP to send mail from localhost?
Greetings.
I've looked through all the old posts on stackoverflow and many on other websites and find lots of posts with the same error, but none of the fixes work.
The following is the error I get:
Mailer Error: Could not instantiate mail function.
Is there something missing or incorrect?
<?php
require '../PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "censored#gmail.com";
$mail->Password = "censored";
$mail->setFrom('censored#gmail.com');
$mail->addReplyTo('censored#gmail.com');
$mail->addAddress('censored#gmail.com');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I found what you're missing.
You need to set these 2 things to get it to work properly:
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
I have a problem, with my code beneath I get this error message:
Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: !Censored!
I have looked into the Host, Port, Username, Password, Recipient and all is correct, what is the problem? Thank you!
Could you please explain too cuz Im new to PHP-coding
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['amne'];
$message = $_POST['message'];
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '!Censored!'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '!Censored!'; // SMTP username
$mail->Password = '!Censored!'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress('!Censored!'); // Add a recipient
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
EDIT: I found the problem, the problem was not in the php code itself. It was in the contact form. The problem started when I put the variables as names and emails. If the email is not verified, it does not work.
This error can be caused by a few different things. You can get a better idea of the reason by adding the following line to your PHPMailer script:
$mail->SMTPDebug = 2; //<-- For debugging
Once you do that, you can check the following things that may be causing the error:
1.) A corrupt class.phpmailer.php file.
2.) The error may be caused by protection put in place by your ISP. Check with them.
3.) It could be a problem with the recipient's/sender's email addresses.
4.) Set SMTPAuth to true for PHPMailer class.
5.) Comment out the following line in your PHPMailer script: $mail->isSMTP();
Mostly, There is possibility that Your phpmailer class file is corrupted.
Download the latest version: https://github.com/PHPMailer/PHPMailer
I am dealing with something strange..
I am setting phpmailer and if I have an error I get the error normally
echo "Mailer Error: " . $mail->ErrorInfo;
actually if everything is good, the page loads a while and then it stops loading, getting in chrome the error: ERR_EMPTY_RESPONSE (Impossible to load the page because the server didn't load the data)
This is the content
<?php
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 645;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myemail#gmail.com"; // SMTP username
$mail->Password = "my password"; // SMTP password
$email = 'myemail#gmail.com';
$mail->From = $email;
$mail->AddAddress("to#example.com", "Name");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject of the mail";
$mail->Body = "content";
$mail->AltBody = "content";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
of course I have included this files:
require_once('../library/class.phpmailer.php');
require_once('../library/PHPMailerAutoload.php');
Two mistakes - just load the autoloader, that loads the class for you so that's all you need.
You've set Port = 645; I suspect you meant 465.
For gmail you should follow the example from the docs: use Port = 587 and SMTPSecure = 'tls'.
you need to Upload the PHPMailer to 6.5.
beacause the php 7.x it's diferent
look that the code change a little bit
I downlaoded a mailer file from https://github.com/PHPMailer/PHPMailer and tried to used in my program to send email, but it lead me to some error . first let have a look at the code
include 'PHPMailer-master/class.phpmailer.php';
include 'PHPMailer-master/class.smtp.php';
$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 = 'ssl://smtp.gmail.com';
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "........#gmail.com";
$mail->Password = "*****";
$mail->SetFrom('.....#gmail.com');
$mail->Subject = "Test";
$mail->Body = "this the mail for subscription";
$mail->AddAddress('......#gmail.com');
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
after running this code i get the error message as:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1546610735)SMTP Connect() failed. Mailer Error: SMTP Connect() failed.
please let me know the problem, as i have seen other post...but i did not get any hint
Just replace
$mail->Host = 'smtp.gmail.com';
No need to specify the SSL here.
for mailing with phpmailer use code like below
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
// optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
You may get complete help from here