Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('WP_USE_THEMES', false);
- require('../../../wp-load.php');
- require_once("class.phpmailer.php");
- if(isset($_POST)) {
- $nome = $_POST["name"];
- $email = $_POST["email"];
- $tel = $_POST["phone"];
- $photos = (!isset($_POST["photos"])) ? NULL : $_POST["photos"];
- $msg = nl2br($_POST["mensagem"]);
- $status = array();
- if(empty($nome)) {
- $status['status'] = '0';
- $status["message"] = 'Digite o nome';
- } elseif(empty($email)) {
- $status['status'] = '0';
- $status["message"] = 'Digite o email';
- } else {
- //formato a mensagem
- $message .= "<b>Nome:</b> \t$nome<BR>";
- $message .= "<b>E-mail:</b> \t$email<BR>";
- $message .= "<b>Telefone:</b> \t$tel<BR>";
- $message .= "<b>Mensagem:</b> \t$msg<BR>";
- //crio um objeto do PHPMailer
- $mail = new PHPMailer();
- //configuração do servidor para rodar o PHPMailer
- $mail->IsSMTP();
- $mail->Host = "localhost";
- //configuro os remetentes
- $mail->From = ""; // email configurado no servidor
- $mail->Sender = ""; // email configurado no servidor
- $mail->FromName = ""; // nome configurado no servidor
- //inclue a mensagem a ser enviada
- $mail->MsgHTML($message);
- if($photos) {
- foreach($photos as $photo) {
- $baseurl = basename($photo);
- //print_r($path);
- $url = parse_url($photo);
- $url = substr($url['path'], -28);
- $mail->AddAttachment(WP_CONTENT_DIR . '/uploads/'.$url, $baseurl);
- }
- }
- $mail->CharSet = 'utf-8';
- $mail->SetFrom($email, $nome);
- $mail->AddAddress("email_que_vai_receber", "nome_do_responsavel_do_email");
- $mail->Subject = ("Titulo do email");
- $mail->AddReplyTo("$email", "$nome");
- if($mail->Send()){
- $status['status'] = '1';
- $status["message"] = 'Enviado com sucessso';
- } else {
- $status['status'] = '0';
- $status["message"] = $mail->ErrorInfo;
- }
- }
- echo json_encode($status);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement