I am tying to send an email with an attachment using phpmailer.
include_once('/home/site/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.free.fr"; // SMTP server
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = "name#sub.fr";
$mail->FromName = "name";
$mail->Subject = "subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("sub#sub.net", "name");
$mail->AddAttachment("mylist.csv"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I receive a "Message sent !" on execution, but no email is ever received.
It is very possible the user you sent the email to did not recieve it due to the fact a lot of mail providers such as AOL and Yahoo block massive amounts of Ip addresses related to email spam. So if the server you are running this php script from is on their blacklist the user will not even receive it to the spam folder.
Check your php email logs.
http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-03.html
Also, if this is not the case, try making sure the file your trying to include exists, and you are passing the correct path to the file. Like #Waygood said, try seeing if it sends without the attachment.
Related
Can anyone tell me, how send email from PHPMailer not using SMTP? This class includes the method isMail() and it should send an email using the mail() function instead SMTP. I'm use Xaamp. When I use SMTP server it's not working all.
My code:
$mail=new PHPMailer();
$mail->IsMail();
$mail->From = 'xxxx#email.com';
$body = "Test body message";
$mail->AddAddress("xxxx#emai.com", "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Send Method returns true and displays message that email has been sent?
The topic is old but for those who will read this.
Try to replace
$mail->isSMTP();
by
$mail->isSendMail();
I have a php page containing PHPMailer. Apperently it was working in both the test server and the production server. It was in a separate php file, but since I need to do send different kinds of email with different alert messages on screen, I placed my code on the same php file as my form.
What I did is:
if(isset($_POST))
{
require_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer(true);
if(isset($_POST['feedback_mail']))
{
$mail->Host = "my mail host"; // SMTP server
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "the account that I will be using"; // SMTP account username
$mail->Password = "my password";
$mail->AddReplyTo($_POST['Email'], $_POST['Name']);
$mail->AddAddress('address to where I will send it', 'Name');
$mail->SetFrom($_POST['Email'], $_POST['Name']);
$mail->Subject = 'Subject'.$_POST['Subject'];
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($_POST['Body']);
$mail->Send();
$marker = 1;
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
$marker = 0;
} else {
$marker = 1;
}
}
}
When I try to send an email message, it says that the message is sent, but I have been waiting for almost an hour but there is still no message recieved on my email. I know that my test server allows sending of email because I also have another application that can send mails. And I am using the same account for sending these mails. How do I know if PHPMailer is really working or not?
EDIT: I found out it might probably be my local network connection that's stopping the mail. I just tried running the from on a VPN connection and somehow it recieved an email.
Either my network connection is having problems or the server is deliberately blocking IP's from my country.
i use phpmailer for sending emails. in one script, the code works fine, in other exaple, result is true, but no mail is delivered. error log is empty, what would you recommend to check?
thanks
include_once '/var/www/xxxxxx.cz/web/php/phpmailer.php';
$to = 'dubcznic#gmail.com';
$to_name = '';
$from = 'robot#xxxxxx.cz';
$from_name = 'Robot';
$mail = new phpmailer();
$mail->CharSet = 'UTF-8';
$mail->From = $from;
$mail->FromName = $from_name;
$mail->AddAddress($to, $to_name); // Add a recipient
$mail->AddCC('nabytek-safr#xxxx.cz');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Import Robot Autronic';
$mail->Body = 'xxx';
$mail->AltBody = str_replace("<br />", "\n", 'xxx');
if (!$mail->Send())
{
echo 'Mail Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo 'OK';
}
die();
Check what text you are sending. It could be that your results are being filtered out and put in a Spam folder. Sometimes a mail with 'test' in the title could be sent right to Spam.
It is impossible to verify that an email was delivered with PHP.
Check your mail server log (usually /var/log/mail) to see if the email was sent.
Send a BCC to an email address that you know has no spam filters.
You can validate real emails with Telnet and MX records. See this answers
https://stackoverflow.com/a/17332773/468891
First, check your spam, if you haven't already.
Second, change your SMTP settings to that of gmails, put your gmail log in and password and try.
If a mail fails to deliver you'll get an delivery- failure notification with possible causes of failure, which helps a lot. A delivery failure can also happen when no error is displayed in PHP.
This always helps me.
I'm trying to send a simple email using phpmailer.
I really have no idea if it's relevant since I'm just doing a php script, but I have apache2 & sendmail, apache2 running and sendmail include in the php.ini (sendmail_path=etc).
So here is my code :
<?php
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "<h1>Coucou</h1>";
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("totest#test.com","First Last");
$mail->SetFrom('fromtest#test.com', 'First Last');
$mail->AddReplyTo("totest2#test.com","First Last");
$address = "XXXX#gmail.com";
$mail->AddAddress($address, "XXXXX");
$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("./test.doc"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
So the thing is that my output is always "Message sent!", even if the script take a really long time to be executed (up to 10minutes !), but the mail never arrived to my mailbox (and I checked the spam folder).
Well I hope someone will have an explanation to that annoying problem!
Thank you anyway.
Regards,
Bdloul
I have this phpmailer which is blasting emails and when recieving the email the sender is : myemail#myemail.com via web258.opentransfer.com (my host)
thats my code:
// Real Email Blast:
$mail = new PHPMailer();
$mail->From = "myemail#email.com";
$mail->FromName = "myname";
$mail->AddAddress($email, $name);
$mail->Subject = $htmlTitle = stripslashes($reSubject);
$mail->Body = $htmlBody = "
<div style='direction: rtl; text-align: right;'>
".stripslashes($reEmailContents)."
</div>";
// Setting plain text:
$text_body = $htmlTitle."
".strip_tags($htmlBody);
$mail->AltBody = $text_body;
if (!$mail->Send()) {
// Email failed error, resending user to landing page:
$error .= "<span style='color: #D20005;'>- Failed sending email to: ".$email." (".$name.")</span><br>";
}
that's especially visible on outlook and on gmail when you access the email itself you can see it on the sender box - how can I remove this and send without the host?
That's the intention of the "via yourdomainhere.com"
I don't believe you can change it, unless you run a custom mail server on your site (which may not be possible on a shared host)
Irregardless, your question would probably be better suited for ServerFault since PHPMailer isn't the issue.