Article focus on part responsible for creating a post and resending them to a subscribers. List of subscribers is also shown.
Form part
Sending of separate information messages to subscribers is enabled by mailer.php page. Form part of the page consist from two filed. Simple input text filed for subject. Second much bigger textarea for gaining text of message from page admin.
<textarea onfocus=“this.value=““ id=“message“ name=“message“ class=“form-control“ rows=“10″ cols=“50″><?php echo isset($_POST[‚message‘]) ? $message : ‚Your text goes here …‘; ?></textarea>
</div>
<button type=“submit“ name=“submit“ class=“btn btn-warning“> Send to subscribers </button>
<button type=“submit“ name=“reset“ class=“btn btn-info“> Reset form </button>
Interesting part of code is inserted in input tag onfocus=“this.value=““ that enable clearing information „value“ text inserted into a form field.
Sending e-mail-s
Part for sending a e-mails is inserted into a HTML body because we will produce messages after all succesfully sent e-mails. Full code can be obtainted for further reference and study from github here.
<?php // if message to send was submitted then emails are sent mail by mail
// Control if data was submitted
if(filter_has_var(INPUT_POST, ‚submit‘)){
// $subject and $message was aded to variables in scrit on upper part of page, because we expect outpu about sending email
// in body of page thic code is inserted in html body part of code
// Controll if all required fields was written
if(!empty($subject) && !empty($message)) {
// If check passed – all needed fields are written
echo “ cannot be send, please examine your email server connection! </p>„;
}
}
echo „<br>“;
// Free result set – free the memory associated with the result
mysqli_free_result($output);
} else{
echo „There is no subscriber in mailinglist. Please add them.“; // if no records in table
}
} else{
echo „ERROR: Could not able to execute $sql. “ . mysqli_error($dbc); // if database query problem
}
// Close connection
mysqli_close($dbc);
} else {
// Failed – if not all fields are fullfiled
$msg = ‚Please fill in all contactform fields‘;
$msgClass = ‚alert-danger‘; // bootstrap format for allert message with red color
};
};
?>
Listener of subscribers part
Our next php code part is responsible for showing list of subscribers in form of a table. For styling of the output, some css was added to style.css file (github link is here).
<?php // code showing all subscribers in form of a table at end of the page
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user ‚root‘ with no password) */
We inform you that we use cookies and other technologies on this site to function and improve the operation of the site, ensure it, provide social networking features, personalize content and ads to users, and analyze traffic and user behavior. For more information, please read our Terms of Use and Cookies. You can prevent cookies from being processed by changing the settings in your Internet browser.OkPrivacy policy