Error sending emails, giving a form submission error

0
<?php
if(!isset($origin, $content, $to))
    exit();
if(!isset($titleName) || $titleName == NULL) {
    $titleName = "";
} else {
    $titleName = " por ".$titleName;
}
$phpmailer = true;
$from = array(
    "name" => "IOCM",
    "host" => "mail.email.com.br",
    "user" => "nao-responda",
    "email" => "[email protected]",
    "password" => ""
);
#$to = "[email protected]";
if($phpmailer) {
    include_once("class.phpmailer.php");
    $mail           = new PHPMailer();
    $mail->IsSMTP();
    $mail->IsHTML(true);
    $mail->CharSet  = "UTF-8";
    $mail->SMTPAuth = true;
    $mail->Port     = 587;
    $mail->Host     = $from['host'];
    $mail->Username = $from['user'];
    $mail->Password = $from['password'];
    $mail->From     = $from['email'];
    $mail->FromName = $from['name'];
    $mail->SMTPDebug= 2;

    # ADDING MAILS /*
    if(!is_array($to))
        $to = array($to);
    foreach($to as $to_) {
        if(is_string($to_))
            $mail->AddAddress($to_);
        elseif(is_array($to_) && isset($to_['name'], $to_['email']))
            $mail->AddAddress($to_['email'], $to_['name']);
    }
    #/ADDING MAILS */
    if(isset($_FILES, $_FILES['curriculo'])) {
        if($_FILES['curriculo']['error'] != UPLOAD_ERR_OK) {
            exit("Ocorreu uma falha inesperada ao tentar enviar o seu currículo. Por favor, tente novamente com outro arquivo.");
        }
        $mail->AddAttachment($_FILES['curriculo']['tmp_name'], $_FILES['curriculo']['name']);
    }

    $mail->WordWrap = 50;
    $mail->Subject  = "Solicitação via formulário '".$origin."'".$titleName;
    $mail->Body     = $content;
    $send = $mail->Send();
} else {
    define('UPLOAD_LIMIT', 2000000); # 2MB
    define('SEMI_RAND', uniqid());
    define('MIME_BOUNDARY',  "==Multipart_Boundary_x".SEMI_RAND."x");
    function getFile($i) {
        if(!isset($_FILES, $_FILES[$i])) {
            return false;
        }
        $allowed = array("csv", "pdf", "jpg", "png", "JPG", "PNG", "jpeg", "JPEG", "doc", "xls");
        $temp = explode(".", $_FILES[$i]['name']);
        $extension = end($temp);
        $mimes = array('application/vnd.ms-excel', 'text/plain', 'text/csv', 'text/tsv', 'image/jpg', 'image/png', 'image/gif');
        if($_FILES[$i]['size'] >= UPLOAD_LIMIT) {
            exit("Sentimos muito, mas esse arquivo ultrapassa o nosso limite de 2MB. Por favor, selecione outro arquivo.");
        } elseif(
            !in_array($_FILES[$i]['type'], $mimes)
            || !in_array($extension, $allowed)
        ) {
            exit("Sentimos muito, mas não aceitamos o formato de arquivo que você tentou enviar. Por favor, selecione outro arquivo.");
        } elseif($_FILES[$i]['error'] > 0) {
            exit("Ocorreu uma falha inesperada ao tentar subir esse arquivo. Por favor, tente novamente mais tarde.");
        }
        $file = fopen($_FILES[$i]['tmp_name'], "rb");
        $data = fread($file, filesize($_FILES[$i]["tmp_name"]));
        fclose($file);
        $cvData = chunk_split(base64_encode($data));
        return "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$_FILES[$i]['name']."\"\n" . "Content-Disposition: attatchment;\n" . " filename=\"".$_FILES[$i]['name']."\"\n" . "Content-Transfer-Encoding: base64\n\n" . $cvData . "\n\n" . "--".MIME_BOUNDARY."\n";

    }
    $attatchContent = getFile("curriculo");
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    if($attatchContent !== false) {
        $headers.= "Content-type: multipart/mixed;\n" . " boundary=\"".MIME_BOUNDARY."\"";
        $content = "--".MIME_BOUNDARY."\n" . "Content-Type: text/html; charset=\"utf-8\"\n". "Content-Transfer-Encoding: 7bit\n\n" .$content. "\n\n" . "--".MIME_BOUNDARY."\n" . $attatchContent;
    } else {
        $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    }
    $headers .= 'To: '.$to . "\r\n";
    $headers .= 'From: '.$from['name'].' <'.$from['email'].'>' . "\r\n";
    $send = mail($to, "Solicitação via formulário '".$origin."'".$titleName, $content, $headers);
}
exit($send ? "OK" : "NO");

? >

    
asked by anonymous 29.08.2018 / 20:05

0 answers