Need Help With PHP Email

Discussion in 'Blogging' started by hari4u2, Jul 13, 2015.

  1. hari4u2

    hari4u2 Regular Member

    Joined:
    Jun 23, 2010
    Messages:
    201
    Likes Received:
    45
    Gender:
    Male
    Occupation:
    Business
    Location:
    India
    Home Page:
    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 ?
     

    Attached Files:

  2. JamesHere

    JamesHere Jr. VIP Jr. VIP

    Joined:
    Jan 24, 2013
    Messages:
    782
    Likes Received:
    677
    Occupation:
    Instant Social Media Services at Retention Panel
    Location:
    retentionpanel.com
    Home Page:
    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);
    ?>
    
     
    • Thanks Thanks x 1
    Last edited: Jul 13, 2015