Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using php script to send two emails to two different places 1

Status
Not open for further replies.

gameon

Programmer
Feb 23, 2001
325
GB
Hi, I am using php to let people recommend my site to other people.

I'm using the following code:

<?php

$recipient = &quot;<$sender_email>&quot;;
$subject = &quot;$sender_name recommended the Mp3Players.co.uk web site&quot;;

$mailheaders = &quot;From: web@mp3players.co.ukn&quot;;
$mailheaders .= &quot;Reply-To: web@anon.com\n\n&quot;;

$msg = &quot;Hi, $sender_name recommended \n&quot;;

mail($recipient, $subject, $msg, $mailheaders) or die (&quot;Couldn't send mail!&quot;);
header(&quot;Location: emailed.htm&quot;);

?>

This gets it's variables from a form:
<form name=&quot;form1&quot; action=&quot;email.php3&quot; method=&quot;post&quot; >


I would also like the same variables sent to another php script, that reports who has recommended the site to whom.

Is it possible to post the variables to two php files, or get the php file to send two emails, both with different content and recipients, but using the same variables?

Cheers,

Matt
 
Yes you can send more than one e-mail from within one page. Just take another recipient and message variable, and send it again.

Here's how I would do it:

<?php
$recipient1 = &quot;<$recipient_email>&quot;;
//who gets the recommendation message

$recipient2 = &quot;<$your_email>&quot;;
//your own e-mail address to inform you of a recommendation

$subject1 = &quot;$sender_name recommended the Mp3Players.co.uk web site&quot;;
//The subject for the first mail

$subject2 = &quot;$sender_name recommended the Mp3Players.co.uk web site to &quot;;
//The subject for the second mail

$mailheaders = &quot;From: web@mp3players.co.ukn&quot;;
$mailheaders .= &quot;Reply-To: web@anon.com\n\n&quot;;
//These you can use again

$msg1 = &quot;Hi, $sender_name recommended \n&quot;;
//The message body for the first mail

$msg2 = &quot;$sender_name recommended to $recipient_email\n&quot;;
//The message body for the second mail

mail($recipient1, $subject1, $msg1, $mailheaders) or die (&quot;Couldn't send mail to $recipient_name!&quot;);
mail($recipient2, $subject2, $msg2, $mailheaders) or die (&quot;Couldn't send mail to myself!&quot;);
header(&quot;Location: emailed.htm&quot;);
?>
Hope this helps you out..
 
Hi Mate,
tahnks loads for helping out. I have edited the code to the following:

<?php

$recipient = &quot;<$sender_email>&quot;;
$recipient2 = &quot;mattg@3rd-angle.com&quot;;

$subject = &quot;$sender_name recommended the Mp3Players.co.uk web site&quot;;
$subject2 = &quot;$sender_name recommended the Mp3Players.co.uk web site&quot;;

$mailheaders = &quot;From: web@site.co.uk\n&quot;;
$mailheaders .= &quot;Reply-To: web@site.co.uk\n\n&quot;;

$msg = &quot;Hi, $sender_name recommended that we send you a link to the \n include: bla bla bla\n\n&quot;;

$msg2 = &quot;Hi, $sender_name recommended the site to their mate,who's email address is: mailto:$sender_email\n\n&quot;;


mail($recipient1, $subject1, $msg1, $mailheaders) or die (&quot;Couldn't send mail to $recipient_name!&quot;);
mail($recipient2, $subject2, $msg2, $mailheaders) or die (&quot;Couldn't send mail to myself!&quot;);
header(&quot;Location: emailed.htm&quot;);

?>

However is returns an 'Internal server error'. Have I done something wrong?

Cheers,

Matt
 
Sorry mate, I'm just a morron. I hadn't put the '1's on any of the 1st subjects, or message body's.

Cheers,

Matt

If you ever need help with flash or director, and I can help - please let me know.

mailto:mattg@3rd-angle.com
 
Hi steijssen,
Cheers for helping me this far. It is all working great now! What I was looking at is the possibility of sending an HTML email with php.

Can i just put the code:

$msg = &quot;<html><head><title>Untitled Document</title><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;></head><body bgcolor=&quot;#FFFFFF&quot;>Test</body></html>&quot;;

Cheers,

Matt
mailto:mattg@3rd-angle.com
 
Yes you can, but don't use any double quotes in the message body, use single ones (')
It's just like sending the html to the screen using print or echo, only now you do it in a mail.
 
Cool, so the following would work (in theory)

$msg = '<html><head><title>Untitled Document</title><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;></head><body bgcolor=&quot;#FFFFFF&quot;>Test</body></html>';

And I can put the whole page inbetween

$msg = '..lots of code..';

The page would be about 600 chrs.

Cheers,

Matt
 
better try it this way:

$msg = &quot;<html><head><title>Untitled Document</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head><body bgcolor='#FFFFFF'>Test</body></html>&quot;;

Don't use &quot;&quot; in the text, only ' '
the &quot;&quot; should only be used at the beginning and end of the string

it shouldn't be a prob to put in 600 chars in the message.
If you use a web-editor, copy the html code, and then do a find & replace on the double &quot;
replace it all with a single '
that should do it ;-)
 
Hi Again, So far I changed the script to the following:

<?php

$recipient1 = &quot;<$sender_email>&quot;;
$recipient2 = &quot;mailk&quot;;

$subject1 = &quot;$sender_name recommended the web site&quot;;
$subject2 = &quot;$sender_name recommended the web site&quot;;

$mailheaders = &quot;From: web@m.co.uk\n&quot;;
$mailheaders .= &quot;Reply-To: web@ms.co.uk\n\n&quot;;

$msg1 = &quot;<html><head><title>Untitled Document</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head><body bgcolor='#FFFFFF'><img src=' width='343' height='72'></body></html>&quot;;

$msg2 = &quot;Hi, $sender_name recommended the site to their mate,who's email address is: mailto:$sender_email\n\n&quot;;


mail($recipient1, $subject1, $msg1, $mailheaders) or die (&quot;Couldn't send mail&quot;);
mail($recipient2, $subject2, $msg2, $mailheaders) or die (&quot;Couldn't send mail&quot;);
header(&quot;Location: emailed.htm&quot;);

?>

The email that it sent was:

<html><head><title>Untitled Document</title></head><body bgcolor='#FFFFFF'><img src=' width='343' height='72'></body></html>

which is the string. I don't why. It should just show and image - where the email was...

any ideas....

Matt
 
ack, fcourse it shows just the tags..
try this:

$mailheaders = &quot;From: web@m.co.uk\n&quot;;
$mailheaders .= &quot;Reply-To: web@ms.co.uk\n\n&quot;;
$mailheaders .= &quot;Content-type: text/plain\r\n&quot;;

Now you tell the mailprogram the e-mail is just pure text formatted. I think that should do the trick.
 
Oops better yet:

$mailheaders = &quot;From: web@m.co.uk\n&quot;;
$mailheaders .= &quot;Reply-To: web@ms.co.uk\r\n&quot;;
$mailheaders .= &quot;Content-Type: text/html\r\n&quot;;

the previous reply doesn't do it, I just tested it, and this one does it, it says the mail is in text format suitable for html.
don't forget the \r\n in the Reply-to line.
 
Cheers Mate,
what do you do for a living. There must be something that I can do in return.

It works fantastically!

Cheers,

Matt
mattg@3rd-angle.com
 
Right now, I don't have a job, but will soon sign a contract for webmaster at some webdesign company in Belgium. If I have a prob with Flash I'll contact you without a doubt. :)

Right now, I have a problem with a mysql connection to my server.. but they're already looking after it.

Glad I could help you out lad :)
 
Just to let you see some of the things I've done, (although it is a year old - its still ok. (none of the stuff I'm working on now is ready.)

Check out (make sure you have a look in the interactive zone)

See ya,

Matt
 
ouch that looks great!

I don't know enough flash to make that stuff..

keep up the great work!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top