Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP error??

  • 20-12-2011 1:03pm
    #1
    Registered Users, Registered Users 2 Posts: 4,673 ✭✭✭


    Hi all,

    I've got one little problem with a PHP file that I'm using. I don't know PHP so I don't know where to begin with fixing this and I was hopin you guys could point me in the right direction.

    It's a php file that I'm using that I'm using on another website as well. I've literally copied and pasted the file, but it works on the first website and the second website is throwing up errors. It's a simple formhandler that sends me a message and also sends the user an automated response.

    The code i'm using I got from the Internet a while back and while I can understand most of what is going on, I can't see where the problem is?
    Here's the code:
    <?php
    
    //bring in the form information//
    
    $your_name = $_POST['your_name'];
    $your_email= $_POST['your_email'];
    $your_contactno= $_POST['your_contactno'];
    $your_location= $_POST['your_location'];
    $comments=$_POST['comments'];
    $enquirytype=$_POST['enquirytype'];
    
    //create the message to be sent//
    
    $message ="Hi Jo bloggs! You have a new message from your website! 
    The visitor typed the following:
    
    Name: $your_name
    Email: $your_email
    Number:$your_contactno
    Enquiry Type:$enquirytype
    Comments:$comments";
    
    
    //decide on subject on Email and recepients//
    $subject = "A new message from your website!";
    $my_email= "info@fit4lifecork.com";
    
    //send the mail
    [COLOR="red"]mail($my_email, $subject, $message);[/COLOR]
    
    
    //autoresponder variables//
    $respond_subject = "Thanks for your enquiry at RandomCompany!";
    $respond_message = "Hello $your_name,
    
    Thank you for contacting RandomCompany with your enquiry regarding $enquirytype
    We will be in touch as soon as possible!
    
    Yours sincerely,
    
    Joe bloggs";
    
    //send the auto-response//
    [COLOR="Red"]mail($your_email, $respond_subject, $respond_message);[/COLOR]
    
    
    //redirect page//
    header("location:thanks.html");
    
    ?>
    

    the red lines are the ones that appear to be the problem.
    Any ideas?? The error messages are for the red lines and they're both the same:

    PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing



    Any help much appreciated! :) Thanks a million!


Comments

  • Registered Users, Registered Users 2 Posts: 19,049 ✭✭✭✭murphaph


    I googled your error and the first result was from the PHP manual here: http://php.net/manual/en/function.mail.php

    It says:"Note:

    When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

    Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing."

    So, you need to pass a "from" paramater into the function as well as you apparently have not set a default in your PHP.ini file (that's the php config file)


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Include additional headers:

    [php]
    $headers = 'From: myemail@domain.com' . "\r\n" .
    'Reply-To: myemail@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    //send the mail
    mail($my_email, $subject, $message, $headers);
    [/php]


  • Registered Users, Registered Users 2 Posts: 4,673 ✭✭✭mahamageehad


    Yup thats exactly worked thanks murphaph.

    So the problem is that the other host I was using has a default one of these set up or something like that, and this host doesn't so I need to manually state it. Anyway it works now and I feel more educated! :) Thanks!


  • Registered Users, Registered Users 2 Posts: 4,673 ✭✭✭mahamageehad


    Ah thanks webmonkey, all sorted now! :) Thanks a million for the quick replies! :)


Advertisement