7 Replies - 2121 Views - Last Post: 02 September 2009 - 05:14 PM Rate Topic: -----

#1 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Sending multiple values with mail()

Posted 02 September 2009 - 10:34 AM

Ok Im needing to send 3-4 values through into an email. This is my code below.
mail("REMOVED", $subject, $title, $description, $email, $image);


It sends the first two but thats it. I thought You could use additonal headers but Im unsure of the exact layout. I tried: $headers = $values then mail("REMOVED", $subject, $headers);

Thats doesnt work. How can I send all my fields through mail?

EDIT: Forgot to remove my email.

This post has been edited by sh250080: 02 September 2009 - 10:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Sending multiple values with mail()

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: Sending multiple values with mail()

Posted 02 September 2009 - 11:03 AM

what are you trying to do ? couldnt ylu send ti in the email text and just parse that ?
Was This Post Helpful? 0
  • +
  • -

#3 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 11:08 AM

Im just trying to send an email with the values from a form.
Was This Post Helpful? 0
  • +
  • -

#4 Balmung  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 02-September 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 03:49 PM

Hey, if you are trying to send mail with the mail() function to multiple people you can make an array emails then do a for loop on the email array and call the mail functions.

example:

$emails = array('me@example.com', 'jor@example.com', 'for@example.com');
$subject = "HEY!";
$body = "Yo Man!";

foreach($emails as $email)
{
  mail($email, $subject, $body);
}



or you can call the mail function multiple times! :) depending on what you're trying to do of course!!
Was This Post Helpful? 0
  • +
  • -

#5 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 04:00 PM

I dont need to send it to a bunch of people. I need to send 1 email, to one email address but I nned it to send all my values instead of just two.
Was This Post Helpful? 0
  • +
  • -

#6 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 04:31 PM

You can "join" variables in PHP with a period (.), like so:

$subject = "Yo!";
$field1 = "Hello.";
$field2 = "What's up?";

//What you've litterally requested:
//mail($email, $subject, $field1.$field2);

//An even better looking version:
mail($email, $subject, $field1."\n".$field2);



Pretty easy to understand. The string \n just inserts a new line between $field1 and $field2.

Yours,
Shane~

This post has been edited by ShaneK: 02 September 2009 - 04:32 PM

Was This Post Helpful? 0
  • +
  • -

#7 Balmung  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 02-September 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 04:36 PM

Ah, I misread Sorry then the best way to do this is (if it is a form) is to do the following ( a quick method )


$subject = "Form has beed filled out";

$body = "Hey sh250080, \n
Someone has filled out the form with the following information:\n";

foreach($_POST as $key => $value)
{
   $body .= $key . ": " . $value . "\n";
}

$body .= "\nThanks!"

mail('email@email.com', $subject, $body);



or you can just "hard code" the post data which means you'd have to change it every time you update the form:


$subject = "Form has beed filled out";

$body = "Hey sh250080, \n
Someone has filled out the form with the following information:\n
First Name: $_POST[firstname]\n
Last Name: $_POST[lastname]\n
\nThanks!"

mail('email@email.com', $subject, $body);



Hope that helps :)!
Was This Post Helpful? 1
  • +
  • -

#8 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Re: Sending multiple values with mail()

Posted 02 September 2009 - 05:14 PM

I have one more question. This is my code as of now:
<?php
include('../dbconnect.php');  
$name = $_POST['name'];
$email = $_POST['email'];
$image = $_POST['image'];
$description = $_POST['description'];
	$sql = "INSERT INTO entries (name, email, image, description)
		VALUES
		('$name', '$email', '$image', '$description')";
		!mysql_query($sql)
?>
<?php
$sql1 = "SELECT * FROM entries";
$result = mysql_query ($sql1);

while ($row = mysql_fetch_array($result))
{
$field1= $row["name"];
$field2= $row["email"];
$field3= $row["image"];
$field4= $row["description"];

echo "$field1<br>";
echo "$field2<br>";
echo "$field3<br>";
echo "$field4<p>";

}
?>


Now when I try to add the mail() code I just get a blank page?


EDIT: I fixed it. I just moved my mail() code around to the top.
<?php
include('../dbconnect.php');  
$name = $_POST['name'];
$email = $_POST['email'];
$image = $_POST['image'];
$description = $_POST['description'];

$subject = "Form has beed filled out";
$body = "Hey sh250080, \n
	Someone has filled out the form with the following information:\n
	First Name: $_POST[name]\n
	Email: $_POST[email]\n
	Image URL: $_POST[image]\n
	Description: $_POST[description]\n
	\nThanks!";
mail('REMOVED', $subject, $body);

	$sql = "INSERT INTO entries (name, email, image, description)
		VALUES
		('$name', '$email', '$image', '$description')";
		!mysql_query($sql)
?>
<?php
$sql1 = "SELECT * FROM entries";
$result = mysql_query ($sql1);

while ($row = mysql_fetch_array($result))
{
$field1= $row["name"];
$field2= $row["email"];
$field3= $row["image"];
$field4= $row["description"];

echo "$field1<br>";
echo "$field2<br>";
echo "$field3<br>";
echo "$field4<p>";

}
?>

This post has been edited by sh250080: 02 September 2009 - 06:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1