Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function sendMail($mailFrom, $replyTo, $mailTo, $ccTo, $mailSubject, $mailContent, $mailTemplate)
- {
- // Create a new PHPMailer instance
- $mail = new PHPMailer();
- // Tell PHPMailer to use SMTP
- $mail->isSMTP();
- // Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 0;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- // Set the hostname of the mail server
- $mail->Host = "hostname of your mail server";
- // Set the SMTP port number - likely to be 25, 465 or 587
- $mail->Port = 25;
- // Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- // Secure transfer enabled REQUIRED for GMail
- $mail->SMTPSecure = 'ssl';
- // Username to use for SMTP authentication
- $mail->Username = "username for sending emails";
- // Password to use for SMTP authentication
- $mail->Password = "password for the above username";
- // Set who the message is to be sent from
- $mail->setFrom($mailFrom['address'], $mailFrom['name']);
- // If the reply to values are present
- if (isset($replyTo['address']) && isset($replyTo['name'])) {
- // Set an alternative reply-to address
- $mail->addReplyTo($replyTo['address'], $replyTo['name']);
- }
- // Set who the message is to be sent to
- $mail->addAddress($mailTo['address'], $mailTo['name']);
- // Set who the message is to be cc'd to
- if (count($ccTo) > 0) {
- foreach ($ccTo as $ccToKey=>$ccToValues) {
- $mail->addCC($ccToValues['address'], $ccToValues['name']);
- }
- }
- // If an attachment exists
- if (isset($mailContent['attachment'])) {
- // Add it to the email
- $mail->addAttachment($mailContent['attachment']);
- }
- // Set the subject line
- $mail->Subject = $mailSubject;
- // Define mail message <----------- NB!!!!!!!!
- require_once pS . '/mailers/layouts/'.$mailTemplate.'.email.php';
- // Convert HTML into a basic plain-text alternative body
- $mail->msgHTML($mailMessage);
- // Define basic mail message <----------- NB!!!!!!!!
- require_once pS . '/mailers/layouts/'.$mailTemplate.'.basic.php';
- // Send the message, check for errors
- if (!$mail->send()) {
- return array=>(false, "Mailer Error: " . $mail->ErrorInfo);
- } else {
- return array=>(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement