Error in sending emails , is giving a form sending error

Asked

Viewed 32 times

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");

?>

Essa é a resposta que o servidor me dá ao tentar enviar

  • 1

    Victor, edit the question, post the error. To detail more, use $mail->SMTPDebug= 2;

  • 1

    Dude, first of all, don’t post sensitive data in the world, you might get hurt by this. Remove this password and email from this code.

  • Thank you Vinicius

  • Rbz edited with the image that error that is appearing

  • Authentication error. Really avoid posting sensitive information. Change the password and try again.

  • @Victorgabriel when colleagues talk to change password, it’s serious. I hope you’ve changed, only edit the post is not enough.

  • I suggest to remove everything and to make a test sent a message only with a "Hello World", if it works, then it adds more things, the less things you have, easier to find the problem

  • Yes I changed the password and other things but still the error does not change

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.