www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP form to mail not sending

  1. #1
    Join Date
    Jul 2008
    Posts
    13

    PHP form to mail not sending

    Hi, can anyone help.

    I have used the following script on a number of websites as a simple enquiry form. I have previously had no problems with it at all, until recently. On one of the sites I have built it doesn't seem to work and just keeps coming back with the error message : "There has been an error sending your comments. Please try later."

    Here is my script:

    PHP Code:
    <?php
    $email_to 
    "me@mydomain.com";
    $name $_POST["name"];

    $email htmlspecialchars($_POST['email']);
    if (!
    preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/"$email))
    {
        
    show_error("E-mail address not valid");
    }


    $email_from "me@mydomain.com";
    $message $_POST["message"];
    $email_subject "Website Enquiry";
    $headers =
    "From: $email_from .\n";
    "Reply-To: $email_from .\n";
    $message "Name: "$name "\r\nEmail: " $email "\r\nEnquiry: " $message;
    ini_set("sendmail_from"$email_from);
    $sent mail($email_to$email_subject$message$headers"-f" .$email_from);
    if (
    $sent)
    {
    header("Location: http://www.mydomain.com/thankyou.html");
    } else {
    echo 
    "There has been an error sending your comments. Please try later.";
    }

    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)
    {


    ?>
    Could this be a server issue?

    Any help would be greatly appreciated.

    Cheers,

    Jim

  2. #2
    Join Date
    Jan 2010
    Location
    South Africa
    Posts
    15
    Are you using windows hosting or linux?

    If you are using linux then you can remove the line

    PHP Code:
    ini_set("sendmail_from"$email_from); 
    and try changing the line
    PHP Code:
    $sent mail($email_to$email_subject$message$headers"-f" .$email_from); 
    to

    PHP Code:
    $sent mail($email_to$email_subject$message$headers); 
    If that doesn't work, then it could be a server issue

  3. #3
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    And if it's a server issue, first see if PHP is configured to use the proper MTA including path and arguments and if that's okay check the MTA error log to see what happened.

    If server is *nix a common config for sendmail_path in php.ini is "/usr/sbin/sendmail -t -i". You can check this value in the phpinfo() output also. The error log is typically in /var/log/maillog but if not read docs on your MTA.

    -jim

  4. #4
    Join Date
    Jul 2008
    Posts
    13

    Thank you

    Thank you Pierrdup, that second part did the job.

    Think it is on a Windows Server to be honest but is hosted by someone else so not too sure.

    Thank you though, removing the last 2 parts of the "$sent = " worked.

    Jim

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles