sendmail.php does not work on mobile

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?

Read More

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'; 
    }
}


?>

Related posts

Leave a Reply

2 comments

  1. You must make sure the mobile form has these two elements:

    1. It is being submitted using method="POST".

    2. 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.

    <form ... method="POST">
    ...
        <input type="text" name="email" ... >
    ...
    </form>
    

    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.

  2. 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…

    ‘ . “rn”; $headers .=
    ‘From: ‘ . “rn”; $headers = ‘MIME-Version: 1.0’ .
    “rn”; $headers .= ‘Content-type: text/html; charset=utf-8’ . “rn”;

    $message .= “Name: ” . $name . “

    “; $message .= “Subject: ”
    . $subject . “

    “; $message .= “Email: ” . $email . “
    “; $message .= “Message: ” . $message_text . “
    “;

    mail($to, $subject, $message, $headers, “-f noreplay@info.com“);

    echo 1; }

    if(isset($_POST[‘sendmail’]) && $_POST[‘sendmail’] == 1){
    send_mail(); } ?>