'tellafriend', 'title' => t(variable_get('tellafriend_pagetitle',0)), 'access' => TRUE, 'callback' => 'tellafriend_page', 'type' => MENU_CALLBACK); $items[] = array('path' => 'tellafriend/send', 'title' => t(variable_get('tellafriend_pagetitle',0)), 'callback' => 'tellafriend_send', 'access' => TRUE, 'type' => MENU_CALLBACK); return $items; } /** * Implementation of hook_settings(). */ function tellafriend_settings() { if (variable_get('tellafriend_server', 0)==""){ variable_set('tellafriend_server','localhost'); } if (variable_get('tellafriend_closing', 0)==""){ variable_set('tellafriend_closing','Sincerely,'); } /* $output = form_textarea(t('Message Text'), 'tellafriend_message', variable_get('tellafriend_message', ''), 70, 5, t('This is the text of the sent message. Use plain text only'),'', TRUE); $output.= form_textfield(t('Page Title'), 'tellafriend_pagetitle', variable_get('tellafriend_pagetitle', ''), 70, 200, t('This is the title of the page'),'', TRUE); $output.= form_textfield(t('Email Subject'), 'tellafriend_subject', variable_get('tellafriend_subject', ''), 70, 200, t('This is the subject. Sender\'s name will come first, as in "[Bob Smith] wants you to go to my site!" No need to include space'),'', TRUE); $output.= form_textfield(t('From address'), 'tellafriend_fromaddress', variable_get('tellafriend_fromaddress', ''), 70, 200, t('This is the address that e-mail will come from'),'', TRUE); $output.= form_textfield(t('Top Message'), 'tellafriend_topmessage', variable_get('tellafriend_topmessage', ''), 70, 200, t('This is the page description.'),'', TRUE); $output.= form_textfield(t('Success Page'), 'tellafriend_success', variable_get('tellafriend_success', ''), 70, 200, t('This is where the script will redirect the user upon success.'),'', TRUE); $output.= form_textfield(t('Closing'), 'tellafriend_closing', variable_get('tellafriend_closing', ''), 70, 200, t('Love, Sincerely, etc...'),'', TRUE); $output.= form_textfield(t('Server name'), 'tellafriend_server', variable_get('tellafriend_server', ''), 70, 200, t('SMTP server name. Set to localhost for default.'),'', TRUE); */ $form['tellafriend_message'] = array( '#type' => 'textarea', '#title' => t('Message Text'), '#default_value' => variable_get('tellafriend_message', ''), '#cols' => 70, '#rows' => 5, '#description' => t('This is the text of the sent message. Use plain text only'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_pagetitle'] = array( '#type' => 'textfield', '#title' => t('Page Title'), '#default_value' => variable_get('tellafriend_pagetitle', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('This is the title of the page'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_subject'] = array( '#type' => 'textfield', '#title' => t('Email Subject'), '#default_value' => variable_get('tellafriend_subject', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('This is the subject. Sender\'s name will come first, as in "[Bob Smith] wants you to go to my site!" No need to include space'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_fromaddress'] = array( '#type' => 'textfield', '#title' => t('From address'), '#default_value' => variable_get('tellafriend_fromaddress', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('This is the address that e-mail will come from'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_topmessage'] = array( '#type' => 'textfield', '#title' => t('Top Message'), '#default_value' => variable_get('tellafriend_topmessage', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('This is the page description.'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_success'] = array( '#type' => 'textfield', '#title' => t('Success Page'), '#default_value' => variable_get('tellafriend_success', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('This is where the script will redirect the user upon success.'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_closing'] = array( '#type' => 'textfield', '#title' => t('Closing'), '#default_value' => variable_get('tellafriend_closing', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('Love, Sincerely, etc...'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_server'] = array( '#type' => 'textfield', '#title' => t('Server name'), '#default_value' => variable_get('tellafriend_server', ''), '#size' => 70, '#maxlength' => 200, '#description' => t('SMTP server name. Set to localhost for default.'), '#attributes' => '', '#required' => TRUE, ); return $form; } /** * Generates the form for the page */ function tellafriend_form() { $url = $_SERVER['HTTP_REFERER']; // p.lindstrom $edit = $_POST['edit']; $tellafriend_email = $edit['tellafriend_email']; $tellafriend_name = $edit['tellafriend_name']; $tellafriend_addresses = $edit['tellafriend_addresses']; $tellafriend_personal = $edit['tellafriend_personal']; $top_of_form = '
'; $top_of_form .= '

' . variable_get('tellafriend_topmessage', '') . '

'; /* $form .= form_textfield(t('Your name'), 'tellafriend_name', $tellafriend_name, 70, 128, t('Your name as it will appear in the sent e-mail.'), '', TRUE); $form .= form_textfield(t('Your e-mail address'), 'tellafriend_email', $tellafriend_email, 70, 128, t('Your e-mail address as it will appear in the sent e-mail.'),'', TRUE); $form .= form_textarea(t("Your friend's e-mail addresses, separated by commas"), 'tellafriend_addresses', $tellafriend_addresses, 70, 5, t('Seperate addresses with commas.'), '', TRUE); $form .= form_textarea(t("Personal message"), 'tellafriend_personal', $tellafriend_personal, 70, 5, t('Adds a personal message to the top of the email.')); // textarea: $output .= $func($field->title, $field->name, $value, 64, 5, $field->explanation . $error); $form .= form_submit(t('Send!'), 'send'); */ $form['tellafriend_name'] = array( '#type' => 'textfield', '#title' => t('Your name'), '#default_value' => $tellafriend_name, '#size' => 70, '#maxlength' => 128, '#description' => t('Your name as it will appear in the sent e-mail.'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_email'] = array( '#type' => 'textfield', '#title' => t('Your e-mail address'), '#default_value' => $tellafriend_email, '#size' => 70, '#maxlength' => 128, '#description' => t('Your e-mail address as it will appear in the sent e-mail.'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_addresses'] = array( '#type' => 'textarea', '#title' => t("Your friend's e-mail addresses, separated by commas"), '#default_value' => $tellafriend_addresses, '#cols' => 70, '#rows' => 5, '#description' => t('Seperate addresses with commas.'), '#attributes' => '', '#required' => TRUE, ); $form['tellafriend_personal'] = array( '#type' => 'textarea', '#title' => t("Personal message"), '#default_value' => $tellafriend_personal, '#cols' => 70, '#rows' => 5, '#description' => t('Adds a personal message to the top of the email.'), ); $form['send'] = array( '#type' => 'submit', '#value' => t('Send!'), ); // p.lindstrom - add REFERER url to message body $msg_text = str_replace("[link placeholder]",$url, variable_get('tellafriend_message',0)); $_SESSION['msg_text'] = $msg_text; // use this since when we hit SEND, referer will be this page; not last page. $bottom_of_form = "

Message to be sent:


" . nl2br($msg_text) . '
'; //$form .= "

Message to be sent:


" . nl2br(variable_get('tellafriend_message', 0)) . '
'; // $output .= form($form, 'post', url('tellafriend/send')); $form['#method'] = 'post'; $form['#action'] = url('tellafriend/send'); $output = $top_of_form . drupal_get_form('your_form_id', $form) . $bottom_of_form; return $output; } //Process a form, send it using php mail //Process a form, send it using php mail function tellafriend_send() { $edit = $_POST['edit']; $tellafriend_email = $edit['tellafriend_email']; $tellafriend_name = $edit['tellafriend_name']; $tellafriend_addresses = $edit['tellafriend_addresses']; $tellafriend_personal = $edit['tellafriend_personal']; //tellafriend_validate(); $tellafriend_fromaddress = variable_get('tellafriend_fromaddress', 0); $tellafriend_pieces = explode(",", $tellafriend_addresses); //$tellafriend_subject = stripslashes($tellafriend_name) . " " . stripslashes(variable_get('tellafriend_subject', 0)); // p.lindstrom - took out name in subject $tellafriend_subject = stripslashes(variable_get('tellafriend_subject', 0)); if(strlen($tellafriend_personal)) { $email_output .= "Personal Message: " . $tellafriend_personal . "\n----------------------\n\n"; } $tellafriend_closing = variable_get('tellafriend_closing', 0); // imbed page URL into email msg body $email_output.= $_SESSION['msg_text'] . "\n\n$tellafriend_closing \n\n" . $tellafriend_name . "\n" . $tellafriend_email; //$email_output.= variable_get('tellafriend_message', 0) . "\n\n$tellafriend_closing \n\n" . $tellafriend_name . "\n" . $tellafriend_email; if (tellafriend_validate()) { foreach ($tellafriend_pieces as $v) { $sendaddress = stripslashes(trim($v)); // p.lindstrom - use mail wrapper //mail($sendaddress,$tellafriend_subject,$email_output,"From: $tellafriend_fromaddress"); user_mail($sendaddress, $tellafriend_subject, $email_output, "From: $tellafriend_fromaddress"); } drupal_goto(variable_get('tellafriend_success', '')); }else{ print theme("page", tellafriend_form()); } } // Implementation of hook_validate(). function tellafriend_validate() { $tellafriend_validated = 0; $edit = $_POST['edit']; $tellafriend_email = $edit['tellafriend_email']; $tellafriend_name = $edit['tellafriend_name']; $tellafriend_addresses = $edit['tellafriend_addresses']; $tellafriend_personal = $edit['tellafriend_personal']; if (!strlen($tellafriend_name)) { $tellafriend_validated = 1; form_set_error("tellafriend_name", t('Name is required!')); } if (!valid_email($tellafriend_email)) { $tellafriend_validated = 1; form_set_error("tellafriend_email", t('Email address is not valid!')); } // check all the email addresses given $tellafriend_pieces = explode(",", $tellafriend_addresses); if ((count($tellafriend_pieces)==1) && ($tellafriend_pieces[0]=="")){ $tellafriend_validated = 1; form_set_error("tellafriend_addresses", t('You must enter at least one e-mail address to send to!')); }else{ foreach ($tellafriend_pieces as $v) { $sendaddress = stripslashes(trim($v)); if (!valid_email($sendaddress)) { form_set_error("tellafriend_addresses", t("Send to address '$sendaddress' is invalid")); $tellafriend_validated = 1; } } } if ($tellafriend_validated == 1) { return FALSE; }else{ return TRUE; } } function tellafriend_page() { $content .= tellafriend_form(); // print out $content print theme("page", $content); } ?>