allow visitors to share my content via email
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 7, 2013 (RSS)
By jeffsaitz - March 7, 2013
Hello,
I have a dynamic page of FAQ's on my site. The page looks into the database and shows the visitor all the FAQ's for the category they selected. how do i add a button for the visitors to generate an email that contains a specific FAQ. I can't use a simple "mailto" link because most of my visitors to not have default email applications (outlook, groupwise, etc) on their PC's. I basically want the email to be generated from my server and just prompt the visitor for a recipient's email address.
By gregThomas - March 7, 2013 - edited: March 7, 2013
Hi Jeff,
I would do something like this:
// load records from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => false,
));
$errorsAndAlerts = "";
if(@$_REQUEST['sendMail']){
if(!@$_REQUEST['name']){ $errorsAndAlerts = "You must enter your name"; }
if(!@$_REQUEST['email']){ $errorsAndAlerts = "You must enter your e-mail address."; }
if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "You must enter a valid e-mail address"; }
if(!$errorsAndAlerts){
$mailRecord = mysql_get('blog', $_REQUEST['blogNum']);
if(@$mailRecord['num'] > 0){
$mailMessage = "Hi ".htmlencode($_REQUEST['name']);
$mailMessage .= "<br><br>";
$mailMessage .= "Below is the FAQ question you requested:";
$mailMessage .= "<br><br>";
$mailMessage .= $mailRecord['content'];
$mailMessage .= "<br><br>";
$mailMessage .= "Thanks";
$mailMessage .= "<br><br>";
$mailMessage .= "Site Admin";
$errors = sendMessage(array(
'from' => "test@example.com",
'to' => $_REQUEST['email'],
'subject' => "Your FAQ",
'html' => $mailMessage,
));
}
}
}
?>
<p><?php echo $errorsAndAlerts; ?></p>
<?php foreach($blogRecords as $blog): ?>
<form action="" method="post" >
<p><?php echo $blog['title']; ?></p>
<input type="hidden" name="sendMail" value="yes" />
<input type="text" name="name" placeholder="Name" value="" />
<input type="text" name="email" placeholder="E-mail" value="" />
<input type="hidden" name="blogNum" value="<?php echo $blog['num']; ?>" />
<input type="submit" name="submit" value="Submit" />
<br/>
<hr/>
</form>
<?php endforeach; ?>
This is just example code using a blog section I have set up on my test installation, so you'll need to make a few changes to get working on your site.
So each FAQ that is displayed will have a form that contains the record number for the submitted FAQ question, along with the users name and e-mail address.
If the sendMail value is detected, then the code validates the users name and e-mail address. If both of these are valid then the CMS Builder sendMessage function is used to send a message with the requested FAQ to the user. The correct record to send is retrieved using the mysql_select function.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com