Closed (duplicate)
Project:
E-mail This Page
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Jun 2006 at 17:52 UTC
Updated:
6 Nov 2006 at 22:09 UTC
This module has so many problems, I don't even know where to start. But here are two functions I rewrote/added to the module to make it "work". If you would like help with rewriting the rest of it contact me. My fix requires phpMailer. I'm sure if you now this but M$ and Yahoo block most mail sent with mail(). phpMailer is a dependable library that solves those problems. Futher the script below also places node information on the page. This might not yet be perfect but at lease it works.
function emailpage_mail($from_email, $from_name, $to_email, $to_name, $subject, $body){
global $ml;
if(!is_object($ml)){
include_once('phpmailer/class.phpmailer.php');
$ml = new PHPMailer();
}
if(is_object($ml)){
$ml -> IsMail();
$ml -> From = $from_email;
$ml -> FromName = $from_name;
$ml -> AddAddress($to_email, $to_name);
$ml -> Subject = $subject;
$ml -> Body = $body;
if ($ml ->send()){
$ml->ClearAddresses();
return true;
}
else{
$ml->ClearAddresses();
return false;
}
$ml->ClearAddresses();
}
}
function emailpage_page() {
global $base_url;
// first we check to see if they have reached the emailpage_flood_control limit
// which is set in the settings.
if($_COOKIE['emailpage_flood_count'] >= variable_get('emailpage_flood_control', 10)) {
$content = variable_get('emailpage_flood_error_msg', t('Sorry, you have reached the maximum number of emails allowed per user. Please try again later'));
print theme('page', $content);
return;
}
$host = parse_url($base_url);
// Check we have the $node-nid needed to send the page
// and the comment fragment if they email a comment
//////////////////////////////////////////////////////////////////////////
// MODIFIED CODE -- JUNE 22 2006
// Noone qualified the nid and cid variables as being integers
// Node/Comment information not available
/////////////////////////////////////////////////////////////////////////
$nid = intval(urldecode($_GET['nid']));
$cid = intval(urldecode($_GET['cid']));
if(!$_COOKIE['referer']) {
if($nid) {
if($cid) { // this takes care of links to specific comments
$nodelink = $base_url . url('node/'. $nid ."#comment-". $cid);
} else {
$nodelink = $base_url . url('node/' .$nid);
}
// Set the refering page in a cookie
// 5mins should be enuf for anyone to put in a valid email address ;-)
setcookie('referer', $nodelink, time()+300, '/', '.'.$host['host']);
} else {
//Original code: $nodelink = $base_url;
if(empty($nid)){
drupal_goto($host['host']);
}
}
} else {
//Cookie is set so we go get node information from the cookie
$refer_p = explode('/', $_COOKIE['referer']);
$nid = intval($refer_p[4]);
}
if(!empty($nid)){
$node = node_load($nid);
} else {
drupal_goto($host['host']);
}
// we need to check if the form has been posted..
if($_POST) {
if(!user_validate_mail($_POST['edit']['emailpage_addy']) && $_POST['edit']['emailpage_sender'] ) {
//THE FOLLOWING COMMENTED CODE IS THE ORIGINAL FOR THIS MODULE
//$headers = 'Reply-To: '. variable_get('emailpage_sender_addy', ''). "\r\nFrom: ". variable_get('emailpage_sender_addy', ''). "\r\n";
//$headers = "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $headers;
//mail($_POST['edit']['emailpage_addy'], $_POST['edit']['emailpage_sender'].' '. mime_header_encode(EMAILPAGE_SUBJECT_LINE), $_COOKIE['referer']. "\n\n". wordwrap(str_replace('%someone', $_POST['edit']['emailpage_sender'], EMAILPAGE_MESSAGE), 72), $headers);
$body = $_COOKIE['referer']."\n\r".wordwrap(str_replace('%someone', $POST['edit']['emailpage_sender'], EMAILPAGE_MESSAGE));
$emailpage = emailpage_mail( //from email
"no-reply@jbs.org",
//from name
$_POST['edit']['emailpage_sender'],
//to email
$_POST['edit']['emailpage_addy'],
//to name
'',
//Subject
$_POST['edit']['emailpage_sender']." ".mime_header_encode(EMAILPAGE_SUBJECT_LINE),
//Body
$body
//end function call
);
//END MODIFICATIONS
// Delete the cookie
// If we dont do this, sending other pages becomes messy.
setcookie('referer', '', time()-3600, '/', '.'.$host['host']);
// Increase the emailpage_flood_control cookie (check settings)
setcookie('emailpage_flood_count', $_COOKIE['emailpage_flood_count']+1, time()+7200, '/', ".".$host['host']);
$content=variable_get('emailpage_success_msg', t('Success!'));
variable_set('emailpage_total', variable_get('emailpage_total', 0)+1);
//Return the user to their article.
drupal_goto($_COOKIE['referer']);
return;
} else {
$error="<p class=\"error\">You must supply your name and a valid email address</p>";
if($node){
$content .= "<h2>$node->title</h2>";
$content .= "<p>$node->teaser<p>";
}
$form["emailpage_sender"] = array(
'#type' => 'textfield',
'#title' => t("Your Name"),
'#default_value' => $_POST['edit']['emailpage_sender'],
'#size' => 20,
'#maxlength' => 30,
);
$form["emailpage_addy"] = array(
'#type' => 'textfield',
'#title' => t("Address to send to"),
'#default_value' => $_POST['edit']['emailpage_addy'],
'#size' => 20,
'#maxlength' => 30,
);
$form["emailpage_submit"] = array(
'#type' => 'submit',
'#value' => t("Send it Now!"),
);
form_set_error('', t('You must supply your name and a valid email address.'));
$form['#method'] = "post";
$form['#action'] = url("emailpage");
$content .= '<h2>'. t('Example Email')."</h2>\n";
$content .= '<p><strong>'. t('Subject'). ': </strong>['. t('Your Name').'] '.EMAILPAGE_SUBJECT_LINE."</p>\n\n<p>".$nodelink."</p>\n\n<p>[".t('Your Name').'] '.nl2br(EMAILPAGE_MESSAGE).'</p>';
$form['emailpage_stuff'] = array('#type' => 'markup', '#value' => $content, '#weight' => -1);
return drupal_get_form('emailpage', $form);
}
}
if(!$_POST) {
if($node){
$content .= "<h2>$node->title</h2>";
$content .= "<p>$node->teaser<p>";
}
$content .= '<h2>'. t('Example Email'). "</h2>\n";
$content .= '<p><strong>'. t('Subject'). ': </strong>['. t('Your Name'). '] '. EMAILPAGE_SUBJECT_LINE. "</p>\n\n<p>". $nodelink. "</p>\n\n<p>[". t('Your Name'). '] '. nl2br(EMAILPAGE_MESSAGE). '</p>';
$form['emailpage_stuff'] = array('#type' => 'markup', '#value' => $content);
$form["emailpage_sender"] = array(
'#type' => 'textfield',
'#title' => t("Your Name"),
'#default_value' => $_POST['edit']['emailpage_sender'],
'#size' => 20,
'#maxlength' => 30,
);
$form["emailpage_addy"] = array(
'#type' => 'textfield',
'#title' => t("Address to send to"),
'#default_value' => $_POST['edit']['emailpage_addy'],
'#size' => 20,
'#maxlength' => 30,
);
$form["emailpage_submit"] = array(
'#type' => 'submit',
'#value' => "Send it Now!",
);
return drupal_get_form('emailpage', $form);
}
}
Comments
Comment #1
zoo33 commentedPlease check out this rewrite: 63624 which solves most or all of the current problems with this module.
Comment #2
darren oh