Skip to content

bachors/PHP-sending-emails-to-multiple-recipients

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP-sending-emails-to-multiple-recipients

PHP sending emails to multiple recipients with AJAX (client side).

Sample PHP sending email:

# message header
$headers = "From: " . $_POST['to'] . "\r\n";
if(!empty($_POST['cc'])){
    $headers .= "CC: " . $_POST['cc'] . "\r\n";
}
if(!empty($_POST['bcc'])){
    $headers .= "BCC: " . $_POST['bcc'] . "\r\n";
}
if($_POST['type'] == 'html') {
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
}

send message

if(mail($_POST['to'], $_POST['subject'], $_POST['compose'], $headers)) { $result['status'] = 'success'; } else { $result['status'] = 'error'; }

# config SMTP
$config['protocol']     = 'smtp';
$config['smtp_host']     = 'mail.host.com';
$config['smtp_port']     = 123;
$config['smtp_crypto']    = 'tls';
$config['smtp_user']     = 'me@host.com';
$config['smtp_pass']     = 'xxxxxxx';
if($_POST['type'] == 'html'){
    $config['mailtype']     = 'html';
    $config['charset']         = 'iso-8859-1';
}
$this->load->library('email', $config);

message header

$this->email->from('me@ibacor.com', 'iBacor'); $this->email->to($_POST['to']); if(!empty($_POST['cc'])){ $this->email->cc($_POST['cc']); } if(!empty($_POST['bcc'])){ $this->email->bcc($_POST['bcc']); } $this->email->subject($_POST['subject']); $this->email->message($_POST['compose']); if($_POST['type'] == 'html'){ $this->email->set_mailtype("html"); }

send message

if($this->email->send()) { $result['status'] = 'success'; } else { $result['status'] = 'error'; }

# config SMTP
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->Host = 'smtp1.example.com;smtp2.example.com';
$mail->SMTPAuth = true;         
$mail->Username = 'user@example.com';  
$mail->Password = 'secret';         
$mail->SMTPSecure = 'tls';      
$mail->Port = 587;           

message header

$mail->setFrom('me@ibacor.com', 'iBacor'); $mail->addReplyTo($_POST['to']); if(!empty($_POST['cc'])){ $mail->addCC($_POST['cc']); } if(!empty($_POST['bcc'])){ $mail->addBCC($_POST['bcc']); } if($_POST['type'] == 'html'){ $mail->isHTML(true);
} $mail->Subject = $_POST['subject']; if($_POST['type'] == 'html'){ $mail->Body = $_POST['compose']; }else{ $mail->AltBody = $_POST['compose']; }

send message

if(!$mail->send()) { $result['status'] = 'success'; } else { $result['status'] = 'error'; }

This form builth with:

- bootstrap - fontawesome - select2 - tinymce

Releases

No releases published

Packages

No packages published