Jump to content

Mail() function problem


atticus

Recommended Posts

Alright, the mail() is working fine until I add more than five input fields to be sent.  The error I received said that php imposes a limit of five for the mail() function.  My solution was to create a string of the information and just send the string.  However, I think I have the syntax wrong.  Any suggestions would be great, thanks.

 

<?php
$email = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];
$customeremail = $HTTP_POST_VARS['customeremail'];
$address1 = $HTTP_POST_VARS['address1'];
$address2 = $HTTP_POST_VARS['address2'];
$city = $HTTP_POST_VARS['city'];
$state = $HTTP_POST_VARS['state'];
$zip = $HTTP_POST_VARS['zip'];

$content = $address1 $address2 $city $state $zip;

...

elseif (mail($email,$subject,$customeremail,$message, $content )) {

Link to comment
https://forums.phpfreaks.com/topic/95951-mail-function-problem/
Share on other sites

This is what I use:

<?php
foreach ($_POST as $key => $val) {
      $_POST[$key] = stripslashes($val);
}
$to = "[email protected]"; // me
$subject = "Your mom.";
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];

// make it look like it's coming from you so it's easier to reply
$headers .= "From: " . $name . "<" . $email . ">\r\n";

ini_set(sendmail_from, $email);
mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);
?>

 

In your code, your $content is just a bunch of variables typed after it. What are you trying to accomplish there? Are you trying to append them together? Because you're not. You need to use the . method.

 

$content = $var1 . $var2 . $var3;

 

And even then it would turnout like this:

$var1 = "Hello";
$var2 = "World";
$var3 = "!";
$content = $var1 . $var2 . $var3; // HelloWorld!

 

And your variables are in the wrong order.

mail($to, $subject, $message, $headers)

 

In your use, you've got the to field and the subject field right. But then for the message you have the customer's email. Then for the headers you have the message. You need to RTM about how mail takes in parameters a bit.

Link to comment
https://forums.phpfreaks.com/topic/95951-mail-function-problem/#findComment-491230
Share on other sites

thanks for the script, however I am still having a problem.  How do I include multiple fields into the message section.  For example, I would like to include info from the input fields of the form such as address and phone.  This is how I tried it, but for some reason its just not working.

 

<?php
foreach ($_POST as $key => $val) {
      $_POST[$key] = stripslashes($val);
}
$to = "[email protected]"; // me
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];

[color=red]$msg = $message . $phone;[/color]

// make it look like it's coming from you so it's easier to reply
$headers .= "From: " . $name . "<" . $email . ">\r\n";

ini_set(sendmail_from, $email);
mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);

Link to comment
https://forums.phpfreaks.com/topic/95951-mail-function-problem/#findComment-491289
Share on other sites

<?php
foreach ($_POST as $key => $val) {
      $_POST[$key] = stripslashes($val);
}
$to = "[email protected]"; // me
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];

$msg = "This is a message from the website!
The message is as follows:
$message

The phone number of the person that sent this to you is: $phone";

// make it look like it's coming from you so it's easier to reply
$headers .= "From: " . $name . "<" . $email . ">\r\n";

ini_set(sendmail_from, $email);
mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);

 

Something like that?

Link to comment
https://forums.phpfreaks.com/topic/95951-mail-function-problem/#findComment-491315
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.