Page 1 of 1

E-Mail-to-Friend-Script by page

Posted: Sun 28. Aug 2005, 16:39
by volkman
I was looking for a script for "email to a friend", that sends the page, and address stuff. Susi was looking for the same stuff, so i wrote a quick-and-dirty php-script for that. Sure someone could improve it.

Copy the script to a file, name it "mailfriend.php" or so and save to root directory. The code:

Code: Select all

<?php
require_once "include/inc_ext/phpmailer/class.phpmailer.php"; // PHP mail class
?>
		
<?php if($_POST["sendafriend"]) { ?> 

		<?php
		$address = $_POST['webaddress'];
		$me = $_POST['full_name_from'];
		$you = $_POST['full_name'];
		
		$mail = new PHPMailer();
		$email_address			= $_POST['email_address'];
		$email_fullname			= $_POST['full_name'];
		$mail->Mailer 			= "smtp";
		$mail->Host 			= "smtp.myserver.com";
		$mail->Port 			= "25";
		$mail->Username 	= "myusername";
		$mail->Password 	= "mypassword";
		$mail->SMTPKeepAlive 	= false;
		$mail->From 		= $_POST['email_address_from'];
		$mail->FromName 	= $_POST['full_name_from'];
		$mail->AddAddress("$email_address", "$email_fullname");
		$mail->Subject = "Cool Website - recommended by $me";
		$mail->Body    = "
  Dear $you!
  I found a cool website, please visit $address 

  Best regards,
  $me
	"; 

		if(!$mail->Send())
			{
			   echo "Error sending Mail!";
			   echo "Mailer Error: " . $mail->ErrorInfo;
		 	  exit;
			}
			echo "Mail successful sent!";
		?>

<?php } else { ?> 		

				
		<?php 
		$coolpage = $_SERVER['HTTP_REFERER'];
		?>
		<br>
		<br>
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>">
			<input type="hidden" name="webaddress" value="<?php echo $coolpage ?>">
			<p>Name of Friend: <input type="text" name="full_name" size="24"> </p>
			<p>E-Mail-Adress of Friend: <input type="text" name="email_address" size="24"> </p>
			<p>My Name: <input type="text" name="full_name_from" size="24"> </p>
			<p>My Email-Adress: <input type="text" name="email_address_from" size="24"> </p>
			<input type="submit" name="sendafriend" value="Send">
		</form>
		

<?php } ?>
I use DEV 1.2.5 and smtp with auth, maybe your configuration is different, the values for server, username and password have to be edited to meet your config.

Create a new structure like "mail-a-friend" with frontenmenu status "hide" and cache off. Create an article under that structure, headline hidden, contenpart "plain text" and insert

Code: Select all

{PHP:mailfriend.php}
there.

Now put a link in your template(s) in Header or Footer or navigation to call that page. The mailform is very basic, Your Frinds Name and Mail and your name and mail. the page url is sitting in a hidden field.

Hope that helps

volkman

Mail to friend : add both sender & recipient to newslett

Posted: Mon 14. Nov 2005, 16:18
by pSouper
Hi all,
I would like to boost this article bacuase I have a new request for an integrated version of it....

I would like a 'send to friend' reptag or content part where both the recipient and the sender's name & email address are added to the newsletter database (additional 'opt in' checkbox if needed)

any thoughts on this?
anyone else think that this would boost thier newsletter list by adding two names for the price of one? :)

Posted: Mon 18. Dec 2006, 23:03
by phalancs
I would never use a script that tries such methods :O

If someone wants to inform a friend I dont think he wants a newsletter...