Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple mail php

Status
Not open for further replies.

kallywag

Technical User
Jul 6, 2004
20
US
I'm making this simple php mail form using the mail() function to send an information request to an email address, and I've got several fields including name, email, phone, title, subject and message. but when i try to run it i get the following message:


Warning: mail() expects at most 5 parameters, 8 given in E:\stromengineering\new\mail.php on line 24


How can I get it to accept more than five parameters?
 
if your trying to post form fields you would need to do it like this:

Code:
##page1.php##

<form action="page2.php" method="post">
<input type="text" name="email">
<input type="text" name="username">
<!-- add more here -->
<input type="submit" value="post">
</form>

##page2.php##

<?php

$e = $_POST['email'];
$u = $_POST['username'];

$message = "Hello $u, your email is $e";
$subject = "Test email";

$themail = mail("someaddress",$subject,$message);

if($themail){
    echo "Successfully sent";
}else{
    echo "Error in sending mail";
}

?>

Hope it helps!


Regards,

Martin

Gaming Help And Info:
 
yes that helps. how do you get the messages "successfully sent" or "error in sending mail" to post on the same page instead of on a new blank white page? As an alternative to that, how do I get it to redirect the user to a 'thankyou.html' page if it is submitted successfully?
 
think i know what you mean

Code:
<?php

if($_POST['beenSub'] == true){

    $e = $_POST['email'];
    $u = $_POST['username'];

    $message = "Hello $u, your email is $e";
    $subject = "Test email";

    $themail = mail("someaddress",$subject,$message);

    if($themail){
        echo "Successfully sent";
    }else{
        echo "Error in sending mail";
    }
    
    header("Location: thankyou.php");
    exit();  //stops all code below from executing otherwise cause an error
}

?>

<form action="<?php echo $PHP_SELF; ?>" method="post">
<input type="text" name="email">
<input type="text" name="username">
<!-- add more here -->
<input type="submit" value="post">
<input type="hidden" name="beenSub" value="true">
</form>

hope it helps

if the header doesn't work, here is a link on how it works!




Regards,

Martin

Gaming Help And Info:
 
If you are using simple mail now, you might want to use a more sophisticated model later. I always highly recommend the PHPMailer class available at sourceforge.
It has all options - from very simple to the most complicated mails with attachments etc., SMTP options, local mail options etc.
That way you don't have to reinvent the wheel and study the RFC ???? for mail protocol, MIME headers etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top