PHP Mailer Code with Multiple Variables Help

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
Nigel1985
Forum Newbie
Posts: 1
Joined: Mon May 25, 2009 10:17 am

PHP Mailer Code with Multiple Variables Help

Post by Nigel1985 »

Hi all,

I am trying to setup this mail script. You can view the form at this page barbarajyoungman.com/Matilda/info.html. Basically, I cant get it to send me all the form values including the calendar date. And, it says I can have more than 5 var so I cant even try to send the time or add a "party size". What can I do ? Also, I can't figure out how to send the javascript calendar date without using the OnFocus to update a text box.

Code: Select all

 
<td>
    <form action="mail.php" method="POST">
    <br /><input type="text" name="name" size=20>
    <br /><input type="text" name="phone" size=20>
    <br /><script>DateInput('orderdate', true, 'DD-MON-YYYY')</script><input type="text" onfocus='this.value=this.form.orderdate.value'  value="Click to update"name="date">
    <br /><input type="text" name="time" size=20>
    <br /><input type="reset" value=" Reset "><input type="submit" value=" Send "></form>
Then, I have the mail.php script

Code: Select all

 
<html>
<head><title>PHP Mail Sender</title>
<style type="text/css">
<!--
body {font-family: Arial, Helvetica, sans-serif;
font-size: 12px}
-->
</style>
</head>
<body bgcolor="#CCCCCC">
<?php
$email = 'kalman.evan@gmail.com';
$subject = 'MATILDA RESERVATION';
$name = $HTTP_POST_VARS['name'];
$phone = $HTTP_POST_VARS['phone'];
$date = $HTTP_POST_VARS['date'];
 
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript&#058;history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript&#058;history.back(1);'>Back</a>";
}
 
elseif (mail($email,$subject,$name,$phone,$date)) {
echo "<h4>Thank you. I will be in touch soon!</h4>";
} else {
echo "<h4>Can't send email</h4>";
}
?>
?>
</body>
</html>
Last edited by Benjamin on Tue May 26, 2009 10:39 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: PHP Mailer Code with Multiple Variables Help

Post by McInfo »

When you post email addresses in examples, as a courtesy to the owner, remember to check "Do not automatically parse URLs" before you submit your post. (Edit: This is unnecessary due to recent forum updates.)

In the form on info.html, there is a hidden input named "orderdate" that is dynamically generated by the Javascript calendar script. The extra text input named "date" is unnecessary. Access the date from PHP using $_POST['orderdate'].

The mail.php script uses the deprecated $HTTP_POST_VARS. Use $_POST instead.

The mail() function is being given incorrect arguments. Here is a simple example of correct usage.

Code: Select all

<?php
die('Do not run this script without first changing the recipients!');
 
$h1 = 'HTML Mail Example';
 
$message = <<<HTML
<html>
<body>
<h1>{$h1}</h1>
</body>
</html>
HTML;
 
$to      = 'a_l_p_h_a@barbarajyoungman.com, Beta <b_e_t_a@barbarajyoungman.com>';
$subject = 'HTML Mail Example';
$headers = 'From: Automated Web Mailer <donotreply@barbarajyoungman.com>'."\r\n"
         . 'Reply-To: donotreply@barbarajyoungman.com'."\r\n"
         . 'Content-Type: text/html; charset=ISO-8859-1'."\r\n"
         . 'X-Mailer: PHP/'.phpversion()."\r\n";
 
mail($to, $subject, $message, $headers);
?>
PHP Manual: mail()

Edit: This post was recovered from search engine cache.
Post Reply