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 } ?>
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}
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