I have a script that sends a mail to validate a form made by a user. It's a professional application so the mail isn't a spam and the users are members of the company.
Now my PHPmailer() function bug once in two randomly. I would like technical help to see if I did something wrong in my PHP code. So first of all, this is what it should do:
1) the user end his form
2) he has to choose who will receive the email (between 3 choices, and he can cross the 3 checkboxes)
3) One mail will be sent to each person he checked, with a simple link to see the result of the form.
But most of the time, I have this error message:
Language String failed to load:
Recipients_failed [mail]
*[Mail] = the email address*
The PHP script stops there, the page doesn't finish loading and the mail isn't send.
for the exemple, we'll say that in the first page we have [mail1], [mail2] and [mail3] who are 3 checkboxes.
Here is my code:
if(isset['[mail1]']){
$mail = new PHPmailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host=*;
$mail->Port=*;
$mail->From='no-reply#*.fr';
$mail->FromName=*;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth=true;
$mail->Username='no-reply#*.fr';
$mail->Password='*';
$mail->AddAddress([mail1]);
$mail->Subject="*";
$mail->Body = utf8_decode("*");
if(!$mail->Send()){
die($mail->ErrorInfo);
}
$mail->SmtpClose();
unset($mail);
}
I think that the code is ok because this works sometimes, but doesn't work sometimes... What should I do? Speak to OVH or there is something I did wrong?
I think your question has nothing to do with PHP.
The error message simply tells you that one of the recipients does not exist - this message does not come from php but from the SMTP server you are using.
However: I don't know why the server shows you an error message "no translation" - you should contact "OVH" and ask.
Related
My client findspace.co.uk is name registered and hosted with Fasthosts. However since the summer they migrated their email to Office365 and since then the PHP mailer form at findspace.co.uk/pages/arrange.php is returning the error
We're sorry - there was a problem sending this email - please try again.
I've tried changing the smtp email host from fasthosts to Office 365:
<?php include_once("../class/class.phpmailer.php"); ?>
<?php
/********************************* INITIALISE PAGE SETTINGS ******************************************/
$page_title = "Contact Us";
$website_name = "Findspace";
$mail_host = "smtp.office365.com"; // email host
$mail_emailsource = "kp#findspace.co.uk"; // from email address
$mail_emailrecipient = "kp#findspace.co.uk"; // recipient
$mail_username = "contact#findspace.co.uk";
$mail_password = "MYPASSWORD";
But it's still not working. I'm no php expert and I can't figure out where things are going wrong. I wonder if it's an Office365 exchange account filtering issue?
Hi Len - I can't seem to find the bit that does the initializing - me just being a bit thick I think. The form has worked for 5 years up until my client changed email hosting to Office365 in the summer so I'm not certain it's the actual form - or perhaps it's the information i'm using for the hostname etc.
The $mail_host setting for that domain is:
findspace-co-uk.mail.protection.outlook.com
The IP is:
213.199.154.87
http://mxlookup.online-domain-tools.com/
I think you should take a look at this page and compare it to how you are initializing phpmailer on your end.:
http://phpmailer.worxware.com/?pg=examplebsmtp
I've been searching for days if not weeks on how to automatically send a simple e-mail in php after a user completes my form. I've tried Pear, PHP mail, Swiftmailer, changed my php.ini, tried different servers and I'm going mad from none of it working. I have not successfully sent one e-mail yet. I've searched endlessly but I still have no idea what to do and why nothing is working.
At the moment I'm using Swiftmailer (second time round). I set up a test page with code:
<?php
require_once 'swift/lib/swift_required.php';
// CREATE TRANSPORT CONFIG
$transport = Swift_MailTransport::newInstance();
// CREATE MSG
$message = Swift_Message::newInstance();
// SET PRIORITY TO HIGH
$message->setPriority(2);
// SUBJECT
$message->setSubject('Subject');
// FROM
$message->setFrom(array('example#btopenworld.com'));
// TO
$message->setTo(array('example#googlemail.com'));
// EMAIL BODY
$message->setBody('Test');
// SEND
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}
?>
Looking at a similar post someone suggested the last part of the code to see errors and my error is:
Failures:Array ( [0] => example#googlemail.com )
No matter what e-mail I change it to (all using e-mails I have, so real e-mails) it doesn't work. If anyone has any help or suggestions it would be hugely appreciated.
example#btopenworld.com
Unless you are using a btopenworld server to send the E-Mail from, this is not going to work. The E-Mails from address needs to be associated with the server you are sending the message from. You can put the BT address into the reply-to header.
Also, SwiftMailer should have a "debug" switch telling you exactly what goes wrong, but I can't find it in the docs right now. Here is a logger plugin for Swiftmailer that should help if all else fails.
I am using the following PHP CODE to send BULK MAIL .But Mails seems to Land in SPAM.I am using "phpmailer" class to send the mail.
require 'mailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "info#gmail.com";
$mail->Password = "Bexwa44Puciz"; // GMAIL password
$mail->AddReplyTo('info#gmail.com', 'Info');
$Appname = 'info.com';
$_subject="Newsletter From: ".$Appname;
$ema=",";
$to_bcc=explode(",",$ema);
$mail->AddCustomHeader($headers);
foreach($to_bcc as $tb){
$mail->AddBCC($tb, $dname);
}
$_body ="News content";//$hid;
$mail->FromName = "info.com";
$mail->From="inf#gmail.com";
$mail->Subject = $_subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($_body);
if($mail->Send()){
echo "Done";
}else {
echo "Failed";
}
I experienced same. My website sends requests for data confirmation to users a few times each day while I do my daily data maintenance. I sent a test message to my Gmail address and found that if you read your mail through Gmail webmail interface it will sometimes tell you Why the message was spammed. Very useful. It gave the reason "A lot of messages from hp19.hostpapa.com were spam". I am on a budget shared server and I assume a hundred other spammers have bought accounts on the same machine as mine and are using it for evil. My site is non-profit so buying a dedicated box to avoid spam is not an option. So...
My solution was to change my CMS to not use PHP mail() at all. Now my CMS simply displays the message and a mailto: link with Subject parameter set. Now my process is to hit CTRL+C, Click the link, CTRL+V, and hit send. Messages are sent from my computer's IP Address (not on any blacklist) using my mail client, Thunderbird.
This takes me just a couple of seconds longer than it did when my CMS used PHP mail() to send the message for me. However I have found I am receiving a lot more replies so I am happy that the vast majority of messages are not getting spam-binned.
I appreciate this manual solution is not appropriate for automated bulk messaging but for small non-profit sites on shared server who trigger each message with a click, I thought it was worth sharing.
There are a number of reasons you could be going into someones spam box. Your email server could be blacklisted due to either you, or another user on your server. You can check it at http://mxtoolbox.com/blacklists.aspx
Also check your SPF records in your DNS
I'm using PHPMailer for a while now and never really had any problems, but last week I installed one of my CMS on a website and the client insisted on having 2 e-mails receiving the contents of the contact form of his website.
Ok, no problem I thought, just adding an e-mail address using the $phpmailer->AddAddress() function. However, adding a second receiver is causing PHPMailer to send the mail twice to both receivers. I tried adding a third receiver to see if I got it three times, but this didn't change anything. So adding 2+ receivers is causing PHPMailer to send the message twice to all receivers.
There's nothing strange in my code. It's a basic PHPMailer example:
$mail = new PHPMailer();
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddAddress("info#address.com");
$mail->AddAddress("info#address.nl");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->Send();
I've ran out of options. I have absolutely no clue where it's going wrong.
Thanks in advance
--
Just some random thought: I noticed the mailer is defaulted by iso-8859-1 and my site is running utf8. Can there be a "silent" redirect by the server itself?
//EDIT, that ^^ solved my problem
//EDIT2:
Ok, it did not.. today the script worked fine (just 1 mail with 2 receivers) but a moment ago the strange behavior started again. Any tips?
// Solution:
ok, I feel quiet stupid! The answer Zulkhaery Basrul came closest to the actual problem! This is what happened: I was sending an e-mail to multiple addresses in the "to" field. For example:
To: A, B, C
Both A/B are my own adresses. In outlook I had some message rules to put e-mails with certain addressees inside a specific folder. Both A and B had this rule.
When I recieved my e-mail, both mails contained both mailaddresses in the to-field. Causing both of the mails to meet the rule requirements for both rules. Thus keeping the original in one folder and creating a copy in the other (twice).
Thanks for thinking tho :)
You can use $SingleTo property.
From PHPMailer docs:
$SingleTo
Provides the ability to have the TO field process individual emails,
instead of sending to entire 'TO addresses'
$mail = new PHPMailer();
$mail->SingleTo = true; //will send mail to each email address individually
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddAddress("info#address.com");
$mail->AddAddress("info#address.nl");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->Send();
Try to add after
$mail->send();
$mail->ClearAddresses();
Ok, if someone runs into this problem like I did:
My website runs in utf-8, PHPMailer uses iso-8859-1 by default. Somehow the script is run in both charsets causing duplicates. Changing the charset in the class.phpmailer.php file to utf-8 solved the problem!
I think these will do the job :)
$mail->SingleTo = true;
$mail->CharSet = "UTF-8";
I tried everything, UTF8 / BOM check on all files, SingleTo-property, CharSet-property.
It didn't work.
I used the "View Details" function from Gmail and saw that my duplicate mails were sent without a subject.
So, I ended up with a very, very dirty fix.
I put this DIRECTLY below the first line of the send function in the class file:
public function Send() {
if ($this->Subject == "") {
return true;
}
// ... rest of code...
}
I ran into the same problem. The one and only right answer is $mail->ClearAllRecipients()
When I used the accepted answer BCC mails were being sent to all recipients.
SingleTo Is not a good idea. It only works with "sendmail" or "mail" transports, not with SMTP. If you use SingleTo with SMTP, this parameter is just ignored without any error or warning, and you may get duplicates.
According to the authors of the library, SingleTo is planned to be deprecated in the release of PHPMailer 6.0, and removed in 7.0. The authors have explained that it's better to control sending to multiple recipients at a higher level: "PHPMailer isn't a mailing list sender". They tell that the use of the PHP mail() function needs to be discouraged because it's extremely difficult to use safely; SMTP is faster, safer, and gives more control and feedback.
But SMTP is incompatible with SingleTo -- that's why the authors of PHPMailer will remove SingleTo, not SMTP.
This question should have a simple, simple answer, but I just can't seem to get it working. Here's the scenario:
I created a php page -> this one: http://adianl.ca/pages/member_application.php. Once the form is completed, it proceeds to http://adianl.ca/pages/member_application_action.php, puts the data into a MySQL db, & thanks the user for their interest. Anyway, the form works perfectly, except for one little thing: whenever someone fills out that form, I want an email to be sent to sbeattie#adianl.ca, informing them that the form was filled out, & the email would include the form components. The problem is, I can NOT get an email to be sent to that address, or any address truth be told. Having a php page send an email should be a simple thing to do, but it's really baffling me.
Can anyone help me with this? This particular problem has been troubling me since yesterday, & if anyone can help me with this...man, thank you soooooo much.
JP
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.adianl.ca"; // SMTP server $mail->From = "webadmin#adianl.ca";
$mail->FromName = "Web Administration [ADIANL]";
$mail->AddAddress("sbeattie#adianl.ca");
$mail->AddCC("justinwparsons#gmail.com"); the #messageBody variable is just a string
If you want to have the email sent using the server's sendmail client, you can use mail.
If you want it to use another mail server, there are extensions to connect to an SMTP server. I use PHPMailer.
If mail doesn't work, it could be that the server is not set up to send email, or it could be that the mail server is rejecting emails sent from php, amongst other reasons.
this code can also be used to email in php so have a look, you can find many more examples of emailing in php look around
?php
$to = "recipient#example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}