Jump to content

send to a friend


mrdeleigh

Recommended Posts

Thanks for the reply

[quote]do you want to send to only one person, or multiple people?[/quote]

multiple if possible but if it is easier with one person i would be happy

[quote]Do you have support for the mail() function?[/quote]

I use  shared hosting so i think so

Thanks
mrdeleigh
Link to comment
Share on other sites

I haven't tested this yet, so I don't know if you'll get any errors or not.

This is the HTML:
[code]<form action="somepage.php" method="post">
One Email per line<br>
<textarea name="emails"></textarea><br>
<input type="submit" name="submit" value="Send">
</form>[/code]

And here would be the PHP:
[code]<?php
$email1 = explode("\n",$_POST['emails']);
foreach($email1 as $emailaddr){
$email = $emailaddr;
$subject = "This Is Your Subject Line";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion();

$message = '<p>This is your message it can have HTML in it</p>';
$mail = mail($email, $subject, $message, $headers);
}
?>[/code]
Link to comment
Share on other sites

Try this:
[code]<?php
$email1 = explode("\n",$_POST['emails']);
foreach($email1 as $emailaddr){
$email = $emailaddr;
$subject = "This Is Your Subject Line";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion();

$message = '<p>This is your message it can have HTML in it</p>
<p><a href="http://sitename.com'.$_SERVER['REQUEST_URI'].'">This Site</a></p>';
$mail = mail($email, $subject, $message, $headers);
}[/code]
?>
Link to comment
Share on other sites

Try this:
[code]<?php
$email1 = explode("\n",$_POST['emails']);
foreach($email1 as $emailaddr){
$email = $emailaddr;
$subject = "This Is Your Subject Line";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$_POST['name']." \r\n" . "X-Mailer: PHP/" . phpversion();

$message = '<p>This is your message it can have HTML in it</p>
<p><a href="'.$_SERVER['HTTP_REFERER'].'">This Site</a></p>';
$mail = mail($email, $subject, $message, $headers);
}[/code]
Link to comment
Share on other sites

In lack of other responce, here is an example of doing a tipform in a new window.

You need to add a javascript function in your head section, then call it upon request (in a link)

Like this (remove spaces between[color=blue] s c r i p t[/color]) on line 4:
[code]
<html>
<head>

<s c r i p t type="text/javascript" language="javascript">
function open_tip_window(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=500,height=500");
}
</script>

</head>
<body>

<?php

// article blah blah
$art_title = "Article title";

?>

<a href="javascript: open_tip_window('send_tip.php?title=<?php echo $art_title; ?>&url=<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>');" title="Tip a friend">Tip a friend</a>


</body>
</html>
[/code]

The above link opens a new window and that window searches for [color=blue]send_tip.php[/color] and we add a query string containing the article title and the article url, these will be used to fill the form (hidden fields) and continue as post to processing.
Also sender email and sender name is added + some very basic minimum validation (included two functions).

[b]Study this[/b]:
[code]
<?php

function trim_value(&$value)
{
  $value = trim($value);
}

function is_email($email)
{
  if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
  {
    return true;
  }
  else
  {
    return false;
  }
}


if(isset($_POST['submit'])) // form is posted
{
foreach($_POST as $name => $value)
{
  ${$name} = strip_tags($value);
}
if(!empty($from_name) && !empty($from_email) && !empty($to_email))
{
if(is_email($from_email))
{
$headers = "From: $from_name <$from_email>\r\n";
$headers .= "Reply-To: $from_name <$from_email>\r\n";
$headers .= "Return-Path: $from_name <$from_email>\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

$subject = "Article tip: $title";
$message = "Article tip from $from_name ($from_email):\r\n\r\nArticle: $title\r\nURL: $url\r\n\r\n";

$to_emails = explode(",", $to_email);
array_walk($to_emails, 'trim_value');

$no = 0;
$report = " emails was sendt:</b><br />";

foreach($to_emails as $to_email)
{
if(is_email($to_email))
{
$mail = mail($to_email, $subject, $message, $headers);

if($mail)
{
  $no++;
  $report .= "<span style=\"color: green\">$to_email</span> OK!<br />";
}
else
{
  $report .= "<span style=\"color: red\">$to_email</span> failed...<br />";
}
}
else
{
  $report .= "<span style=\"color: red\">$to_email</span> not valid email...<br />";
}
}

echo "<b>".$no.$report;
}
else
{
echo "Your email is not valid, no mails where sendt";
}
}
else
{
echo "Not all fields was supplied, no mails where sendt";
}
}
elseif(!empty($_GET['title']) && !empty($_GET['url'])) // show form
{
echo <<<_HTML

<p>Tip a friend, article: <b>{$_GET['title']}</b></p>

<form method="post" action="send_tip.php">

<input type="hidden" name="title" value="{$_GET['title']}" />
<input type="hidden" name="url" value="{$_GET['url']}" />

<p>Your Name:<br />
<input type="text" name="from_name" /></p>
<p>Your Email:<br />
<input type="text" name="from_email" /></p>
<p>Send to email(s) separated with comma (,):<br />
<input type="text" name="to_email" size="60" /></p>

<p><input type="submit" name="submit" value="Mail IT!" /></p>

</form>

_HTML;
}
else
{
  echo "sorry, info missing";
}
?>
[/code]

Note that this example uses comma to separate several recipients.

Kinda providing you with a working version here, but hopefully you can learn some methods (even if this example isn't perfected)
Link to comment
Share on other sites

Probably a blocker, that's the drawback with using pop-ups.
I had to disable mine when testing this example, but it works.

Try to include it as a .js file instead, strangely enough that seems to help.

If not, you will find tonnes of popup examples if you google it. This or another popup script doesn't make a difference.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.