Need Help With PHP Email

hari4u2

Regular Member
Joined
Jun 23, 2010
Messages
201
Reaction score
47
Need Help With PHP Email

Code:
<?php    /* Set e-mail recipient */
    $myemail  = "[email protected]";




    /* Check all form inputs using check_input function */
    $name = check_input($_POST['name'], "Enter your name");
    $subject    = check_input($_POST['subject'], "Enter your subject");
    $email    = check_input($_POST['email']);
    $phone  = check_input($_POST['phone']);
    $message = check_input($_POST['message']);
    
    /* If e-mail is not valid show error message */
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
    {
        show_error("E-mail address not valid");
    }


    /* Let's prepare the message for the e-mail */
    $message = "Hello!


Name: $name
E-mail: $email
Phone: $phone
Subject: $subject


Mail Message:
$message


End of message
    ";


    /* Send the message using mail() function */
    mail($myemail, $subject, $message);


    /* Redirect visitor to the thank you page */
        header("Location: index.html"); 
    exit();


    /* Functions we used */
    function check_input($data, $problem='')
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        if ($problem && strlen($data) == 0)
        {
            show_error($problem);
        }
        return $data;
    }


    function show_error($myError)
    {
    ?>
        <html>
        <body>


        <b>Please correct the following error:</b><br />
        <?php echo $myError; ?>


        </body>
        </html>
    <?php
    exit();
    }
    ?>

if anybody contacts me not showing there email id in mail. its showing my server mail id
what can i do ?
 

Attachments

  • Capture.jpg
    Capture.jpg
    23.8 KB · Views: 6
You may need to add a "From".

Code:
<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$mailheader = "From: ".$_POST["email"]."\r\n";
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


mail($to, $subject, $message, $headers);
?>
 
Last edited:
Back
Top