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
Share on other sites

This is what I use:

<?php
foreach ($_POST as $key => $val) {
      $_POST[$key] = stripslashes($val);
}
$to = "address@domain.tld"; // 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
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 = "jcapshaw@gmail.com"; // 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
Share on other sites

<?php
foreach ($_POST as $key => $val) {
      $_POST[$key] = stripslashes($val);
}
$to = "jcapshaw@gmail.com"; // 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.