Jump to content

sending different email format to different address


nandos

Recommended Posts

Hi,

I'm trying to make an order form in php, basically I want the email to be sent to different email address in different email format, but I'm stuck with the code, can anyone help me with this, please? I've been trying to figure it out for a couple of days but I still can't solve it, my background is not in programming so, I think this must be really easy for programmers, but it's been causing me a headache.

 

Below is the code that I've been stuck.

 

<?PHP

 

/* SUBJECT AND EMAIL VARIABLE */

$emailSubject = ' crystal ashley order form ';

$webMaster = 'tjoengkikitjahyadi@gmail.com, james.k.tj@gmail.com ';

 

 

/* gathering data variable */

 

$emailField = $_POST['email'] ;

$recipientField = $_POST['recipient'] ;

$nameField = $_POST['name'] ;

$phoneField = $_POST['phone'] ;

$codeField = $_POST['code'] ;

$quantityField = $_POST['quantity'] ;

$hearField = $_POST['hear'] ;

$classField = $_POST['class'] ;

$commentsField = $_POST['comments'] ;

 

 

 

$body = <<<EOD

<br><hr><br>

Email : $email <br>

Recipient : $recipient <br>

Phone : $phone <br>

Code : $code <br>

Code : $code2 <br>

Hear from : $hear <br>

Interested in : $class <br>

Comments : $comments <br>

<br>

EOD;

 

$headers = "From : $email\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

 

 

Email : $email <br>

Name : $name <br>

Phone : $phone <br>

Code : $code <br>

Code : $code2 <br>

Hear from : $hear <br>

Interested in : $class <br>

Comments : $comments <br>

<br>

EOD;

 

$headers = "From : $email\r\n";

$headers = "To : $recipient\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

/*results rendered as html*/

$theResults = <<<EOD

<html>

<head>

<title>Real Yoga Enquiry Form</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

body {

background-color: #f1f1f1;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

font-style: normal;

line-height: normal;

font-weight: normal;

color: #666666;

text-decoration: none;

}

-->

</style>

</head>

 

<div>

  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>

</div>

</body>

</html>

EOD;

echo "$theResults";

 

 

?>

Link to comment
Share on other sites

You don't seem to have a clue about PHP, do you? ;)

 

Untested code:

 

<?php
/* SUBJECT AND EMAIL VARIABLE */
   $emailSubject = ' crystal ashley order form '; 
   $webMaster = 'tjoengkikitjahyadi@gmail.com, james.k.tj@gmail.com ';


/* gathering data variable */

   $emailField = $_POST['email'] ;
   $recipientField = $_POST['recipient'] ;
   $nameField = $_POST['name'] ;
   $phoneField = $_POST['phone'] ;
   $codeField = $_POST['code'] ;
   $quantityField = $_POST['quantity'] ;
   $hearField = $_POST['hear'] ;
   $classField = $_POST['class'] ;
   $commentsField = $_POST['comments'] ;



   $body = <<<EOD
<br><hr><br>
Email : $email <br>
Recipient : $recipient <br>
Phone : $phone <br>
Code : $code <br>
Code : $code2 <br>
Hear from : $hear <br>
Interested in : $class <br>
Comments : $comments <br>
<br>
EOD;

   $headers = "From : $email\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);


/*results rendered as html*/
   $theResults = <<<EOD
<html>
<head>
<title>Real Yoga Enquiry Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
   background-color: #f1f1f1;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
   font-style: normal;
   line-height: normal;
   font-weight: normal;
   color: #666666;
   text-decoration: none;
}
-->
</style>
</head>

<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
   $headers = "From : $email\r\n";
   $headers = "To : $recipient\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($recipient, $emailSubject, $theResults, $headers);
?>

 

Basically, I just removed a block of useless, repeated HTML code and sent the second mail using $theResults variable to $recipient.

Link to comment
Share on other sites

It works!! Thanks a lot Sean. :D

 

Yes, I'm learning PHP at the momment, I'm a total beginner in PHP. Do you have a clue why the "from header" says "nobody" when I receive the reply mail in the mail inbox?

Link to comment
Share on other sites

does anybody know what code I have to type in if I want the $theResults and $theReply code not in the same email format

 

<?PHP

 

/* SUBJECT AND EMAIL VARIABLE */

$emailSubject = ' crystal ashley order form - squares ';

$webMaster = 'tjoengkikitjahyadi@gmail.com, james.k.tj@gmail.com ';

 

 

/* gathering data variable */

 

$emailField = $_POST['email'] ;

$nameField = $_POST['name'] ;

$phoneField = $_POST['phone'] ;

$codeField = $_POST['code'] ;

$quantityField = $_POST['quantity'] ;

$hearField = $_POST['hear'] ;

$classField = $_POST['class'] ;

$commentsField = $_POST['comments'] ;

 

 

 

$body = <<<EOD

<br><hr><br>

Email : $email <br>

Name : $name <br>

Phone : $phone <br>

Code : $code <br>

Code : $code2 <br>

Hear from : $hear <br>

Interested in : $class <br>

Comments : $comments <br>

<br>

EOD;

 

$headers = "From : $email\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

/*results rendered as html*/

$theResults = <<<EOD

<html>

<head>

<title>Real Yoga Enquiry Form</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<div>

  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>

</div>

</body>

</html>

 

EOD;

  $headers = "From : $email\r\n";

  $headers = "To : $recipient\r\n";

  $headers .= "Content-type: text/html\r\n";

  $success = mail($recipient, $emailSubject, $theResults, $headers);

 

 

 

 

 

 

 

 

$theReply = <<<EOD

<html>

<head>

<title>Real Yoga Enquiry Form</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<div>

  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>

</div>

</body>

</html>

 

 

echo "$theReply";

 

 

?>

Link to comment
Share on other sites

   $headers = "From : $email\r\n";
   $headers = "To : $recipient\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($recipient, $emailSubject, $theResults, $headers);

 

In the second line in the above block of code, change the = to .=, which will effectively append the To field to the $headers variable. It is currently "overwriting" the From in the $headers variable, causing the mail to be from nobody.

 

I don't understand your question... from what I understand, you are sending an email to the webmaster using $body, another email to the user using $theResults, and displaying a page to the user using $theReply. What are you trying to achieve?

Link to comment
Share on other sites

Thanksss alott for the help!

I would like to send 2 email format to the buyer, one is to let them know that the order has been sent after the submit button, another one sent to their email to let them know that they will receive an order confirmation.  Do you have any idea how i can do that?

Link to comment
Share on other sites

You currently have 2 email formats:

 

The first shows all the fields (email, name phone) and their values, and is currently sent to the webmaster. I'll assume that this is correct and require no further changes.

 

The second displays the message "Thank you for your interest! Your email will be answered very soon!", and is sent to the email address stored in the variable $recipient. This format is also displayed in the browser because you do have an echo "$theReply"; at the bottom.

 

Now, I'll assume that this second message is the same one that "(lets) them know that the order has been sent after the submit button".

 

And where is the code/text for the "email to let them know that they will receive an order confirmation"? Will this email be sent at the same time as the previous email? Do let me know if my assumptions are wrong.

Link to comment
Share on other sites

Yes your assumption is right, the order confirmation email will be sent at the same time. I've made two 2 email formats, $theResults will be displayed on web browser after buyer click the submit button and $theReply will be sent to their email address, but I'm seeing this error message http://www.crystalashley.co.nz/order-form/contactformprocess-edit.php , do you know what's wrong with my code? I've amended the from header but I don't get why I'm still seeing nobody from "the mail from header" , please help thanksss

 

 

<?PHP

/* SUBJECT AND EMAIL VARIABLE */
$emailSubject = ' crystal ashley order form - squares '; 
$webMaster = 'tjoengkikitjahyadi@gmail.com, james.k.tj@gmail.com ';


/* gathering data variable */

$emailField = $_POST['email'] ;
$nameField = $_POST['name'] ;
$phoneField = $_POST['phone'] ;
$codeField = $_POST['code'] ;
$quantityField = $_POST['quantity'] ;
$hearField = $_POST['hear'] ;
$classField = $_POST['class'] ;
$commentsField = $_POST['comments'] ;



$body = <<<EOD
<br><hr><br>
Email : $email <br>
Name : $name <br>
Phone : $phone <br>
Code : $code <br>
Hear from : $hear <br>
Interested in : $class <br>
Comments : $comments <br>
<br>
EOD;

$headers = "From : $email\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);




/*results rendered as html*/
$theResults = <<<EOD
<html>
<head>
<title>crystal ashley form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>






$theReply = <<<EOD
<html>
<head>
<title>crystal ashley form</title>
</head>

<div>
  <div align="left">Thank you for your interest! Your order confirmation will be sent very soon!</div>
</div>
</body>
</html>



EOD;
   $headers = "From : $webMaster\r\n";
   $headers = "To : $recipient\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($recipient, $emailSubject, $theReply, $headers);



echo "$theResults";


?>

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.