New to PHP, help with a basic mail script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
licwid
Forum Newbie
Posts: 1
Joined: Fri Jun 12, 2009 10:19 am

New to PHP, help with a basic mail script

Post by licwid »

I have a basic mail script that runs without errors, but does not send me an email. Its not being spam filtered I checked, I'm just not receiving it at all.

Code: Select all

<?php
    $to         = 'my@email.address';
    $from       = $_REQUEST['Email'];
    $name       = $_REQUEST['Name'];
    $company    = $_REQUEST['Company'];
    $phone      = $_REQUEST['Phone'];   
    $subject    = $_REQUEST['Subject'];
    $message    = $_REQUEST['Message'];
    $headers    = "From: $from";
    $body       = "Name: $Name \nCompany: $company \nPhone: $phone \n$message";
 
    if(!$from || !$name || !$message) {print "You have not completed all the required fields, please go back and try again";}
    else 
    {
        $send = mail($to, $subject, $body, $headers);
        if($send) 
        { 
            echo "<script language=\"JavaScript\">\n";
            echo "alert(\"Your E-Mail was sent successfully.\");","\n";
            echo "window.location = 'ReDirect URL'";        
            echo "</script>"; 
        }
        else 
        { 
            echo "<script language=\"JavaScript\">\n";
            echo "alert(\"We encountered an error sending your mail, please notify me.\");","\n";
            echo "window.location = 'ReDirect URL'";        
            echo "</script>";           
        }
    }
?>
Any ideas?

Thanks
-Licwid
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: New to PHP, help with a basic mail script

Post by akuji36 »

Post Reply