Page 1 of 1

php mail

Posted: Mon Dec 08, 2008 4:27 pm
by peterj
Hi,
When a user enquires about a product, I want 1 email to be sent to the seller with the below information attached to the email ($recipient, $subject, $body, $headers), but I also want an invoice style email to be sent to the buyer with slightly different content in the $body. How do I send emails to 2 different people with different $body content?

Thanks

<?php
$recipient = "email@domain.com";
$product = $_POST['product'];
$model = $_POST['model'];
$code = $_POST['code'];
$price = $_POST['price'];
$productID = $_POST['productID'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$enquiry = $_POST['enquiry'];
$subject = "Website Enquiry about $model";
$body = "

Product Details: \n
Product Brand: \t $product \n
Product Model: \t $model \n
Product Code: \t $code \n
Product ID: \t $productID \n\n
Personal Details: \n
Name: \t $name \n
Email:\t $email \n
Phone:\t $phone \n
Enquiry:\n

$enquiry
";

$headers = "From: $email \n";
$mailSent = mail($recipient, $subject, $body, $headers);
if (!$mailSent) {
header("Location:product_detail.php?id=".$productID."&status=There was an issue sending your enquiry. Sorry");
} else {
header("Location:product_detail.php?id=".$productID."&status=".$model." has been successfully been enquired about");
}


?>

Re: php mail

Posted: Tue Dec 09, 2008 1:20 am
by maneetpuri
Hi,

The best solution is creating a function for sending email. This function should take three parameter – To, From and Body

Now you can call this function twice both with different parameters and both the mails will be sent but with different body messages.

Hope this help.

Cheers,