Urgent Help Required in PHP forms: Someone please rescue me!!!!

He has: 71 posts

Joined: Nov 2006

I am using this script to send mail from my site:

<?php
$name
=$_POST['name'];
$school=$_POST['school'];
$class=$_POST['class'];
$email=$_POST['email'];
$number=$_POST['number'];
$to=\"[email protected]\";
$message=\"Application For Voluntary Work\n\nName: $name \nSchool: $school \nClass: $class \nEmail Address: $email \nMobile Number: $number\";
if(mail(
$to,\"Application For Voluntary Work\",$message,\"From: $email\n\")) {
echo \"Thanks
$name,<br>Hamza Sardar Malik will contact you soon.\";
} else {
echo \"There was a problem sending the mail. Please check that you filled in the form correctly.\";
}
?>

the form is not mailed to me when i use $to= "[email protected]" how ever it works when i replace this hotmail email with my pop3 email of the website's domain.... is there some error in my script or its that my hosting provider has blocked some feature......

i called him to ask if some feature is blocked and he said that every thing is functional and nothing is blocked...

1) so can someone pleasee edit this script to enable get mail on a non-POP3 email address like hotmail yahoo and gmail.

2) also please tell me what changes do i have to make to send mail to two different email addresses.....

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

It may not be that your host is blocking mail going to hotmail, hotmail may be blocking e-mail coming from a php generated e-mail. Try setting a header to change what gets sent as the e-mailing program. (See example #2 on http://www.php.net/manual/en/function.mail.php )

Also, before your script goes live for people to use, I ighly suggest you do error checking on the values you are getting from the $_POST variable.

-Greg

mik-crap's picture

He has: 30 posts

Joined: Jan 2007

I'd also suggest you clear up your syntax. Firstly, your variables are messy. Secondly, if(mail) doesn't mean anything.

What do you mean make it to get email on a non-POP3 email address? Make what exactly?

Here's your code. I've made it more legible and added the checking process. This script is in no-way as complex as it could be or as securely as it could. Hopefully it will be a starter for you though.

<?php
 
// get values
   
$name = $_POST['name'];
   
$school = $_POST['school'];
   
$class = $_POST['class'];
   
$email = $_POST['email'];
   
$number = $_POST['number'];
 
 
// recipient
   
$recipient = \"[email protected]\";
   
$recipient2 = \"[email protected]\";
 
  // our message - take values from _POST
   
$message = \"Application For Voluntary Work\n\nName: $name\nSchool: $school\nClass: $class\nEmail Address: $email\nMobile Number: $number\";
 
  // check we have values
    if (!isset(
$name && $school && $class && $email && $number)) {
      // return error
        echo 'You must complete all fields.';
        die;
    }
   
    else {
        // check we have mail enabled
         if (function_exists(mail)) {
           // send mail
             mail(
$recipient, \"$name's Application For Voluntary Work\", $message, \"From: $email\r\n\" . \"\r\n\" . \"CC: $recipient2\");
             echo 'Thank you for emailing Hamza Sardar Malik';
       }
      
       else {
        echo 'mail() function not enabled';
        die;
       }
    }
?>

Perhaps you should check to see if hotmail is sending it to your spam folder.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.