I'm getting the "From" email dynamically through a form that gets populated on page load using $email = $_POST['company_email'];
When I add the variable to the line $mail->From
in phpmailer the script runs successfully, but no mail is received. If I enter a value statically (eg test@email.com), it works and the Reply To email even displays the dynamic address.
I've narrowed it down to just being the $mail->From
line that causes the issue. Has anyone run into this before?
I'm using PHPMailer as is: https://github.com/PHPMailer/PHPMailer
I've simplified it down to almost nothing for testing purposes:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$to = $_POST['send_to'];
$company_name = $_POST['company_name'];
$company_email = $_POST['company_email'];
$email_type = $_POST['email_type'];
$subject = '';
$mail->From = 'from@email.com'; // <-- this is the line that's causing the issue
// when changed to $company_email, no mail is received
$mail->FromName = $company_name;
$mail->addAddress($to); // Name is optional
$mail->addReplyTo($company_email, $company_name);
$mail->Subject = $subject; //'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
EDIT: I've found that it doesn't like yahoo email addresses. I left the email address the same, only changed "yahoo" to "mail" and then "gmail" and it worked. Is the server seeing the yahoo address as spam then?