I trying to make a tell a friend script.
The script must send an email to the address the user specifies in the form field. containing the link of the current page in the mail body.
I tried a lot of scripts and mail classes like phpmailer, etc..
But couldnt make any of them works...
Can someone help me?
UPDATE: this is my current code
<?php
require_once 'Mail.php';
$from = "xxx@xxxx.com.";
$to = $_POST["email"];
$subject = "Pear mail test";
$body = "testing pear mail. if you are reading this, it is working.";
$host = "smtp.xxxxxx.com";
$username = "xxx@xxxx.com.";
$password = "xxxxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => '587',
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
<form action="<?php echo $PHP_SELF?>" method="post">
<fieldset>
<legend>Recomendar</legend>
<label for="nome">Nome</label><input name="nome" size="40" type="text" />
<label for="email">E-mail:</label><input name="email" size="40" type="text" />
<input type="submit" value="Enviar" />
</fieldset>
</form>
it works, but the script is activated when loading the page (return a recipient error), how can i make the script run only when user press the submit button?