Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP send mail script is annoying me

    I am really getting annoyed here. Could anybody help me figure out the problem?

    Go to http://surfacehawaii.com/contactus.html
    Fill out the form and submit.

    See?

    Here is the php code

    PHP Code:
    <?php
    if(isset($_POST['submit']))*{
    *

    $to*=*"caleb@surfacehawaii.com";
    $subject*=*"Contact Form";
    $name_field*=*$_POST['name'];
    $email_field*=*$_POST['email'];
    $message*=*$_POST['message'];
    *
    foreach(
    $_POST['check']*as*$value)*{

    $check_msg*.=*"Checked:*$value\n";

    }
    *
    $body*=*"From:*$name_field\n*E-Mail:*$email_field\n*Message:\n*$message\n*$check_msg";*
    mail($to,*$subject,*$body);*

    if*(
    mail($to,*$subject,*$body))*//if*the*mails*sent
    {*header(Location*:*"http://www.surfacehawaii.com/thanks.html");
    }
    //page*to*redirect*to*if*your*email*was*sent
    else
    {*echo*
    "Sorry.*Error*sending*message!";}*//show*that*email*could*not*be*sent**

    ?>
    If anyone could help, that would be great.

  • #2
    Registered User
    Join Date
    Apr 2006
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK
    New php script, but still have a problem.

    PHP Code:
    <?php*
    $to*=*"caleb@surfacehawaii.com";
    $Subject*=*"{$_POST['subject']}";
    $message*=*"NAME:*{$_POST['name']}*{$_POST['message']},";
    mail($to,$Subject,$message);
    if(
    mail){
    echo*
    "<BR*/>Thanks,*message*sent";
    }
    else{
    echo*
    "<BR*/>*An*Error*occured";
    }
    ?>
    Thanks in advance for your patience.

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    You should have looked at the PHP documentation.

    The mail function signature is specified as follow.
    PHP Code:
    bool mail string tostring subjectstring message [, string additional_headers [, string additional_parameters]] ) 
    Therefore, you need to re-write your script in accordance to the mail function signature. Here is an example

    PHP Code:
    <?php
    $to      
    'caleb@surfacehawaii.com';
    $subject $_POST['subject'];
    $message $_POST['message'];
    $headers 'From: contact@surfacehawaii.com' "\r\n" .
        
    'Reply-To: ' $_POST['name'] . '<'$_POST['email'] .'>' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

    $ok mail($to$subject$message$headers);
    if( 
    $ok ) {
    echo 
    "Thanks, message sent successfully";
    } else {
    echo 
    "Sorry, unable to send email at the moment.";
    }
    ?>
    Note: I took the liberty to define another post variable $_POST['email'], so that when you receive an email, you can easily reply to the person who has emailed you.

    Good luck.
    Ess


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •