Strange issue – my sendmail.php is working perfectly on desktop and on mobile devices only when requesting desktop websites (in Chrome app), but when using mobile site he does not work at all.
Can someone help me figure this out?
here is the code:
<?php
if(isset($_POST['email'])) {
if (!check_email($_POST['email']))
{
echo 'Please enter a valid email address<br />';
}
else send_email();
}
exit;
function check_email($emailAddress) {
if (filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
function send_email() {
$message = "nName: " . $_POST['name'] .
"nEmail: " . $_POST['email'] ;
$message .= "nMessage: " . $_POST['comment'] .
"nnBrowser Info: " . $_SERVER["HTTP_USER_AGENT"] .
"nIP: " . $_SERVER["REMOTE_ADDR"] .
"nnDate: " . date("Y-m-d h:i:s");
$siteEmail = $_POST['receiver'];
$emailTitle = $_POST['subject'];
$thankYouMessage = "Thank you for contacting us, we'll get back to you shortly.";
if(!mail($siteEmail, $emailTitle, $message, 'From: ' . $_POST['name'] . ' <' . $_POST['email'] . '>'))
{
echo 'error';
}
else
{
echo 'success';
}
}
?>
You must make sure the mobile form has these two elements:
It is being submitted using
method="POST"
.Your email input has the attribute and value
name="email"
.I demonstrate where these things are set in the following code. This is incomplete, of course, it’s just designed to show you where the two required parts must be.
I need to mention one more thing …
That being said, what you’re doing here is EXTREMELY INSECURE. You are allowing someone to set an email’s from and two address on a web form. A (not so) clever hacker can easily write a script to turn your server into an open relay for spam or other evil activities. At minimum, you should remove
$_POST['receiver']
and replace with with a hard-coded email address or at least not something that can be altered by an end-user when they POST to your form.So I drilled down and found that the mobile form is directing submissions through this PHP file which was 404.
The issue now is, even when this file is avaiable, emails are not sent…