Hi guys, I’m having a very strange problem here. I have a contact form and upon submission it’s supposed to send an email to a specific email address, (it’s a hotmail.com if that’s important). The form submits OK but I don’t receive any email, not even on the junk folder: no errors anywhere. To make sure that I wasn’t making any silly errors in the code, I redirected the form submission to another email address, a hotmail.co.uk, and lo and behold, I do receive an email. Needless to say, I had a good look online, and, although I’m a php beginner it seems that my code doesn’t have any major issue (as I said it works with another email address). I’m a bit confused, and not sure how to resolve that. So, let’s have a quick look at the code (the password has been replaced of course):
[php]
<?php require 'PHPMailer-master/PHPMailerAutoload.php'; //header('Content-Type: application/json'); //SMTP needs accurate times, and the PHP time zone MUST be set //This should be done in your php.ini, but this is how to do it if you don't have access to that date_default_timezone_set('Etc/UTC'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $firstName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $lastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $emailAddress = filter_input(INPUT_POST, 'emailAddress', FILTER_SANITIZE_EMAIL); $message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING); $website = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_URL); $mail = new PHPMailer(true); $mail->Timeout = 30; // set the timeout (seconds) //$mail->isSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "tls"; // sets the prefix to the servier $mail->Host = "smtp.live.com"; // sets hotmail as the SMTP server $mail->Port = 587; // set the SMTP port for the hotmail server $mail->Username = "[email protected]"; // hotmail username $mail->Password = "xxxxxxxxxx"; // hotmail password //$mail->setFrom($emailAddress, $firstName . ' ' . $lastName); $mail->setFrom("[email protected]", "No reply"); $mail->addAddress('[email protected]', 'Rosie'); $mail->Subject = 'New myfavourbox request'; //$mail->Body = $message . "\r\n\r\nWebsite: " . $website; $mail->Body = "First Name: " .$firstName . "\r\n\r\nLast Name: " . $lastName . "\r\n\r\nEmail address: " .$emailAddress . "\r\n\r\nMessage: " . $message . "\r\n\r\nWebsite: " . $website; if(!$mail->send()){ echo "Mailer Error: " . $mail->ErrorInfo; http_response_code(400); } else{ echo "success"; } } ?>[/php]
As mentioned before, if I change the email address (and password of course) in the file from [email protected] to [email protected], I receive the email (even though in the junk email, but let’s leave this last problem for later).
Does anybody have any suggestion? For completeness, here is the website in question, it may or may not be useful, I don’t know:http://antonioborrillo.co.uk/rosie/en/index.php.
Also it’s worth noticing that the form is submitted via ajax, but again, that works, it’s just the email that doesn’t come through. Any help from you guys is much appreciated.
thanks