?
Solved

Tell A Friend

Posted on 2005-04-11
17
Medium Priority
?
730 Views
Last Modified: 2010-08-05
Hi Guys:

Looking to develop a 'Tell A Friend' page with a custom HTML Email that I can put the persons name and address into ? Hope someone can help... I have included both my HTML code the page itself and the Email... :-)

  <table border="0" width="100%">
    <tr>
      <td width="32%" align="right"><b><font color="#4EB24F" face="Tahoma">Your
        Name:</font></b></td>
      <td width="68%"><input type="text" name="txtVisitorName" size="36"></td>
    </tr>
    <tr>
      <td width="32%" align="right"><b><font color="#4EB24F" face="Tahoma">Your
        Email:</font></b></td>
      <td width="68%"><input type="text" name="txtVisitorEmail" size="36"></td>
    </tr>
    <tr>
      <td width="32%" align="right"><b><font color="#4EB24F" face="Tahoma">Friends
        Name:</font></b></td>
      <td width="68%"><input type="text" name="txtFriendName" size="36"></td>
    </tr>
    <tr>
      <td width="32%" align="right"><b><font color="#4EB24F" face="Tahoma">Friends
        Email:</font></b></td>
      <td width="68%"><input type="text" name="txtFriendEmail" size="36"></td>
    </tr>
    <tr>
      <td width="100%" colspan="2" align="center"><font color="#FFFFFF" face="Tahoma" size="1">Please
        Note: Email addresses are <u>not</u> recorded for advertising (SPAM)
        purposes!&nbsp;</font></td>
    </tr>
  </table>
  <p><input type="submit" value="Send Email" name="cmdSend"><input type="reset" value="Reset" name="cmdRest"></p>
</form>



--------
Email:


<html>

<head>
<meta http-equiv="Content-Language" content="en-au">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>[ Tell A Friend Email ]</title>
</head>

<body link="#0F8A3E" vlink="#0F8A3E">

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="200"><img border="0" src="menu_images/logo.jpg" width="200" height="357"></td>
    <td width="100%">
      <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#0C1C0C">
        <tr>
          <td width="17" valign="top"><img border="0" src="menu_images/top_left.gif" width="17" height="18"></td>
          <td width="100%" align="center"><img border="0" src="menu_images/headerlogo.jpg" width="80" height="15"></td>
          <td width="17" valign="top"><img border="0" src="menu_images/top_right.gif" width="17" height="18"></td>
        </tr>
        <tr>
          <td width="17">&nbsp;</td>
          <td width="100%">
        <p align="center">&nbsp;<p><b><font color="#FFFFFF" face="Tahoma" size="3">Hi
        &lt;NAME&gt;,</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3">A
            friend of yours, &lt;FRIENDS NAME&gt;, recently visited </font><a href="http://www.address.com" target="ipAlien"><font face="Tahoma" size="3" color="#0F8A3E">www.address.com</font></a><font color="#FFFFFF" face="Tahoma" size="3">
        and thought that maybe you should check it out!</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3"><a href="http://www.address.com" target="ipAlien">address.com</a>
        is a great website and an ad free service!</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3">Regards,</font></b><p>&nbsp;<p><b><font color="#FFFFFF" face="Tahoma" size="3">The
        address.com Team</font></b>
        <p align="center">&nbsp;</td>
          <td width="17">&nbsp;</td>
        </tr>
        <tr>
          <td width="17" valign="bottom"><img border="0" src="menu_images/bottom_left.gif" width="17" height="18"></td>
          <td width="100%">&nbsp;</td>
          <td width="17" valign="bottom"><img border="0" src="menu_images/bottom_right.gif" width="17" height="18"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<p align="center"><font face="Tahoma" size="1">Copyright © <font color="#4EB24F"><a href="http://www.address.com">www.address.com</a></font>
2005 - All Rights Reserved - This Email was sent at the request of the following
address: <a href="mailto:email@email.com">&lt;THE SENDERS EMAIL&gt;</a></font></p>

</body>

</html>
0
Comment
Question by:SR301
  • 5
  • 4
  • 4
  • +3
17 Comments
 
LVL 6

Assisted Solution

by:peyox
peyox earned 60 total points
ID: 13758703
0
 
LVL 6

Accepted Solution

by:
quad341 earned 195 total points
ID: 13759342
easy enough.  

in your top page, make sure you add <form action="NAME_OF_FOLLOWING.SCRIPT" method="post"> with the appropriate script name filled in

SCRIPT:
<?php
$vis_name = $_POST[txtVisitorName];
$vis_addr = $_POST[txtVisitorEmail];
$friend_name = $_POST[txtFriendName];
$firend_addr = $_POST[txtFriendEmail];

// not sure what you want from: to be, so i'll set it to noreply@address.com
$from="noreply@address.com";
// not sure what you want subject. using "Tell a Friend"
$sub="Tell a Friend";
$msg = <<<EOF
<html>

<head>
<meta http-equiv="Content-Language" content="en-au">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>[ Tell A Friend Email ]</title>
</head>

<body link="#0F8A3E" vlink="#0F8A3E">

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="200"><img border="0" src="menu_images/logo.jpg" width="200" height="357"></td>
    <td width="100%">
      <table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#0C1C0C">
        <tr>
          <td width="17" valign="top"><img border="0" src="menu_images/top_left.gif" width="17" height="18"></td>
          <td width="100%" align="center"><img border="0" src="menu_images/headerlogo.jpg" width="80" height="15"></td>
          <td width="17" valign="top"><img border="0" src="menu_images/top_right.gif" width="17" height="18"></td>
        </tr>
        <tr>
          <td width="17">&nbsp;</td>
          <td width="100%">
        <p align="center">&nbsp;<p><b><font color="#FFFFFF" face="Tahoma" size="3">Hi
        &lt;$friend_name&gt;,</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3">A
            friend of yours, &lt;$vis_name&gt;, recently visited </font><a href="http://www.address.com" target="ipAlien"><font face="Tahoma" size="3" color="#0F8A3E">www.address.com</font></a><font color="#FFFFFF" face="Tahoma" size="3">
        and thought that maybe you should check it out!</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3"><a href="http://www.address.com" target="ipAlien">address.com</a>
        is a great website and an ad free service!</font></b><p><b><font color="#FFFFFF" face="Tahoma" size="3">Regards,</font></b><p>&nbsp;<p><b><font color="#FFFFFF" face="Tahoma" size="3">The
        address.com Team</font></b>
        <p align="center">&nbsp;</td>
          <td width="17">&nbsp;</td>
        </tr>
        <tr>
          <td width="17" valign="bottom"><img border="0" src="menu_images/bottom_left.gif" width="17" height="18"></td>
          <td width="100%">&nbsp;</td>
          <td width="17" valign="bottom"><img border="0" src="menu_images/bottom_right.gif" width="17" height="18"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<p align="center"><font face="Tahoma" size="1">Copyright © <font color="#4EB24F"><a href="http://www.address.com">www.address.com</a></font>
2005 - All Rights Reserved - This Email was sent at the request of the following
address: <a href="mailto:$vis_addr">&lt;$vis_addr&gt;</a></font></p>

</body>

</html>
EOF;

$result = mail($friend_email,$sub,$msg,"From: $from");
if ($result){
   // insert html for successfully sent message
$body = <<<EOF
<YOUR HTML HERE>
EOF;
} else {
   // insert html for error message
$body = <<<EOF
<YOUR HTML HERE>
EOF;
}
print $body;
?>
0
 

Author Comment

by:SR301
ID: 13759499
That doesn't really make sense as I don't see how it can send the page...

Happy to increase the points for a solution that fits my problem !
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:SR301
ID: 13759516
If I could just have that main page running the code, and have it grab the Email to send from a template HTML, that would be perfect I think ?
0
 
LVL 2

Assisted Solution

by:Andy_Neodynium
Andy_Neodynium earned 120 total points
ID: 13760268
Mail() will send the email: http://uk2.php.net/manual/en/ref.mail.php

See line above:
$result = mail($friend_email,$sub,$msg,"From: $from");

However, you need to send the email as HTML and Plain Text in one email, if memory serves. There are classes to help with this. There is a good article at:
http://www.developer.com/lang/php/article.php/10941_3468701_1

At it's simplest, you just need to set the headers parameter of the mail function (not used in code above):
 $headers = "MIME-Version: 1.0\r\n";
 $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";

Good example here:
http://www.apptools.com/phptools/forms/forms6.php

(You really do need to support plain text - I NEVER use HTML format mail in my mail reader)
0
 
LVL 2

Expert Comment

by:Marvin_Carredo
ID: 13760591
i concur with what Andy_Neodynium  said, howeverfor the Mail functions to be available,  PHP must have access to the sendmail binary on your system and set proper configuration in the [mail function] of the php.ini
0
 
LVL 2

Expert Comment

by:Marvin_Carredo
ID: 13760618
The DISTINCT clause allows you to remove duplicates from the result set.
The GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns.
0
 
LVL 2

Expert Comment

by:Marvin_Carredo
ID: 13760626
ops! sorry it shud be in the other thread :D http://www.experts-exchange.com/Databases/Mysql/Q_21385039.html
0
 

Author Comment

by:SR301
ID: 13760972
OK - So if I need to handle both HTML and Plain Text, and get either or from an external file, how could I go about it ? I think with my server, I can use the SMTP server... But will double check...
0
 
LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 150 total points
ID: 13761206
For multipart MIME messages (dual format text/HTML) mail() is really not worth the hassle; use PHPMailer instead. It just works and gets all the MIME formatting right without you having to fiddle about with headers, along with things like transfer encodings that's important for HTML. I would go so far as to say that the majority of scripts that use mail() do not produce RFC 2822 compliant messages. It also doesn't require a local sendmail program (though that is the best way to work), and it will also work on Windows servers without any php.ini changes.

There's a simple example of how to do it here:

http://phpmailer.sourceforge.net/tutorial.html

Which comes down to:

<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->From = "from@email.com";
$mail->AddAddress("myfriend@site.com");
$mail->Subject = "look, it's a dual-format message";
$mail->Body = "hi <b>my friend</b>! \n\n this message uses html!";
$mail->AltBody = "hi, this is plain text\n";
?>

No faffing with headers required.

It's not clear how you're expecting your email template to work: it seems that something has done some unnecessary entity substitution in bits like these:

Hi &lt;NAME&gt;
A friend of yours, &lt;FRIENDS NAME&gt;

That just looks broken.
0
 

Author Comment

by:SR301
ID: 13761659
Doesn't look like I can run phpMailer without the host performing a lot of changes which I don't *think* they are going to do... Might have to go for a CGI script !
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13762165
You don't need any server changes or special permissions to run PHPMailer. If you can run PHP, you can use it. All you need to do is upload 2 files with your other scripts (it is only PHP code), and it doesn't require any non-standard PHP extensions. They're even less likely to support a CGI.
0
 
LVL 6

Expert Comment

by:quad341
ID: 13768840
if for some reason you cannot use the mail() function in php, it is very unlikely that you can use sendmail from cgi, as squinky said.  mail should work though.

if not, you could open a socket to the remote mail server and manually send the command, but i think that it would be far more work than worth.  it seems strange that you would not be allowed to the mail function

there is full documentation on the mail standard at w3c as well as many other sites
0
 

Author Comment

by:SR301
ID: 13769125
I'm not sure about the function itself, I was referring to the changes the require in the php.ini which I couldn't seem to find on my account ? Is it something I would need the host to change ?
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13770317
> if not, you could open a socket to the remote mail server and manually send the command, but i think that it would be far more work than worth

PHPMailer has a built-in SMTP class that does exactly this (and supports authentication), so it's actually very easy. As far as I'm aware, you shouldn't need to change anything in php.ini, other than things that you'd need to make mail() work anyway. Even if you don't have access to php.ini itself, you can override its settings in your script:

ini_set('SMTP', 'mail.example.com');
ini_set('sendmail_from', 'me@example.com');
0
 
LVL 2

Assisted Solution

by:Marvin_Carredo
Marvin_Carredo earned 75 total points
ID: 13770820
I'm not sure about the function itself, I was referring to the changes the require in the php.ini which I couldn't seem to find on my account ? Is it something I would need the host to change ?

=============

yes! try to ask your administrator  on what is written in the mail function of the php.ini by default it looks like this:
[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
sendmail_from = postmaster@localhost


try to change ask him to change it to proper configuration like.  

[mail function]
; For Win32 only.
SMTP = <mail server>
smtp_port = 25  //if needed

; For Win32 only.
sendmail_from = <myaccount>@<mydomain>

then perhaps u cud use the mail() function smoothly
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13770907
You can find out what the php.ini settings are by just doing a phpinfo(); To override changes on a shared host (assuming you don't have write access to the actual php.ini), you need to use ini_set, as I suggested. However, as I also said, no matter what you put in php.ini, or what settings you override, mail() does not know how to do SMTP authentication, so it's not going to make any difference.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question