i have a strange problem. I try to send a mail with a pdf document as attachment with php mailer. The script works fine, as long i call it in the browser. When i try to call it from console inside a batch, i'm getting SMTP Error: Data not accepted.
My system is a windows 2008 R2 Server with xampp. The only difference is the user context. When i call the script in the browser, i guess apache will call my script and the apache service is running as lokal system. When i'm starting the batch file the script will probably be called by the user i'm logged in with right ?
Maybe someone could help me out with that problem :)
Greets Mike
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->SetFrom('mymail#outlook.com', 'Me');
$mail->AddReplyTo("mymail#mydomain.com", "Me");
This is my batch:
C:\xampp\php\php-cgi.exe C:\xampp\htdocs\bericht\sendMail2.php
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->SetFrom('mymail#outlook.com', 'Me');
$mail->AddReplyTo("mymail#mydomain.com", "Me");
This is my batch:
C:\xampp\php\php-cgi.exe C:\xampp\htdocs\bericht\sendMail2.php
Related
I've got a bizarre problem here. I'm trying to use PHPMailer to send an email, through SMTP. I have a website hosted by GoDaddy and it's that SMTP account that I'm trying to use to send the mail.
It works if I execute my PHP file on my localhost server.
It does not work if I execute my PHP file on GoDaddy's server.
The error message I get is:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
I checked phpinfo on both localhost and the remote server. Both have smtp_port listed as 25. I'm using WAMP on my machine and the server is some form of Linux (which I know nothing about and have no idea how to administer).
Here is the code in question:
INDEX.PHP:
<?php
date_default_timezone_set('America/Los_Angeles');
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->Port = 25;
$mail->IsSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = 'username#site.com';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result
$mail->ClearAddresses();
$mail->AddAddress('receiver#hotmail.com', 'Receiver Name');
$mail->From = "username#site.com";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";
if ($mail->Send()) {
echo "Message sent!\n";
}
else {
echo "Message failed!\n";
print_r($mail->ErrorInfo);
}
exit();
?>
I think you should perform two step
1) check your port as suggested on godaddy support http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account
2)use "relay-hosting.secureserver.net" as your host instead of "smtpout.secureserver.net"
GoDaddy does allow to send emails using Gmail as your SMTP, just need to get rid of the smtp.gmail.com and use their Host instead. This is my setup:
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account#gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...
Reference (see first two posts) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/
If your hosting has own email server, the server will use the following ports 25,465,587.
Settings for GoDaddy:
$mail->isSMTP();
$mail->Host = localhost;
$mail->SMTPAuth = true;
$mail->Username = 'example#gmail.com';
$mail->Password = 'password';
//$mail->SMTPSecure = 'tls';
//$mail->Port = 587;
For other providers you have to create a mailbox with your domain:
$mail->isSMTP();
$mail->Host = localhost;
$mail->SMTPAuth = true;
$mail->Username = 'example#yourdomain.com';
$mail->Password = 'password';
//$mail->SMTPSecure = 'tls';
//$mail->Port = 587;
Following is my php email code and it works fine still today.
require_once('_lib/class.phpmailer.php');
include 'func/db_connect.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
function supervisorMail(){
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "*****#gmail.com";
$mail->Password = "*****";
$mail->SetFrom("****#gmail.com", "Employee Leave Management System");
}
But now it does not work without any changing of code and it makes following error.
SMTP -> ERROR: Failed to connect to server: (0) SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
I could not able to find the solution. How can I fixed this.
try this it will be work
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "*******#gmail.com";
$mail->Password = "*******";
you have to change in gmail.In Account permissions section, find Access for less secure apps and enable it.
I think you should try by changing the host like this :
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
And also set the other paramters like this :
$mail->SetFrom('contact#example.com', 'User');
$mail->AddReplyTo("example#gmail.com', 'Name Here");
$mail->Subject = "Contact us Email";
$mail->MsgHTML($body);
$address = "user#example.com";
$mail->AddAddress($address, "new user");
if(!$mail->Send()) {
echo "Error in Sending email: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
provide $mail->SMTPDebug=1 itz working [1]: http://i.stack.imgur.com/ZEpjv.png
In my case it was a lack of SSL support in PHP which gave this error.
So I enabled extension=php_openssl.dll
$mail->SMTPDebug = 1; also hinted towards this solution.
For those having the same error:
In my own case, the simple change below solves the problem:
I changed
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
to
$mail->SMTPSecure = 'tls';
You can set it to ssl depending on your SMTP server settings
SMTP -> ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
The following From address failed: info#gmail.com : Called Mail() without being connected.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "name#gmail.com";
$mail->Password = "password";
$mail->From = "info#gmail.com";
$mail->FromName = "name.com";
$mail->Subject = "Register";
$mail->MsgHTML($userMsg);
$mail->AddAddress("useremail", "username");
$mail->send();
$mail->ClearAllRecipients();
Am using PHP mailer for sending emails.For individual users and for some groups i am able to send mails but for some other groups the mails are not going.Am using Microsoft exchange server for the mails.And there are no errors shown in the log file in the host.
PHP mailer code:
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'email.domain.com';
$mail->SMTPAuth = true;
$mail->Username = 'username#domain.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('username#domain.com');
$addresses = 'Recipients#domain.com';
$mail->isHTML(true);
Thanks in advance.
My problem is clear, PHPmailer is howing a long text before sending a mail, this is my code (function) :
function sendMail($content){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Port=465; // Enable SMTP authentication
$mail->Username = 'my mail'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug=true;
$mail->From = '****';
$mail->FromName = '******';
$mail->addAddress('******');
$mail->Subject = 'subject';
$mail->Body=$content;
$mail->AltBody ='testing';
$stat=$mail->send();
}
and this is a screenshot :
http://i.imgur.com/kLrC97q.jpg
Thanks
Sorry guys, I noticed that I should turn off debugging :
$mail->SMTPDebug=false;