Form does not send email to another server outside the hosting [duplicate]

0

I'm developing a website with a contact form. The form is very simple only with the fields name, email, message and subject.

I have the site hosted on a server, but I need the form data to be received in an email account on another server, not what is set up in the hosting service.

I tried the php mail function and it did not work, I tried to use the PHPMailer class and an error related to STMP occurred: (SMTP Error: Could not connect to SMTP host.)

You gave the following error:

  

Parse error: syntax error, unexpected end of file in   /home/trweb146/public_html/development/FormEmailPHPMailer/enviar.php   online 61

$erros = "";

if(empty($_POST['nome'])){ $erros .= "O nome deve ser preenchidooo."; }

if(empty($_POST['email']) ){ $erros .= "O E-mail deve ser preenchido."; }else{ $mail = $_POST['email']; /eregi("([._0-9A-Za-z-]+)@([0-9A-Za-z-]+)(.[0-9A-Za-z.]+)",$email,$match); if(!isset($match)){ $erros .= "O e-mail informado é inválido."; }/ }

if(empty($_POST['mensagem'])){ $erros .= "A mensagem deve ser preenchida."; }

if( empty($erros) ){

$mail = new PHPMailer(true);

$mail->IsSMTP();

try{
    $mail->Host = "smtp.trwebsites.com.br";
    $mail->SMTPAuth = true;
    $mail->Port     = 587;
    $mail->Username = "[email protected]";
    $mail->Password = "*****";//aqui coloquei a senha do meu email

    $mail->CharSet = 'UTF-8';
//remetente $mail->SetFrom("[email protected]", "Nome Empresa"); //$mail->AddReplyTo("[email protected]", "Nome Empresa"); $mail->Subject = "Um assunto";

    //destinatários
    $mail->AddAddress($this->emailDestinatario, "nome destinatário");
    $mail->AddCC($this->emailCopia, "Cópia pra fulano");

    $conteudo = "-- Dados --<br/>";
//corpo do e-mail $mail->MsgHTML($conteudo);

    $mail->Send();

    return true;

}catch(phpmailerException $e){
    echo $e->errorMessage();
    return false;
}

Can anyone help me? How can I solve this problem?

    
asked by anonymous 06.12.2017 / 09:41

1 answer

0

Use the same SMTP, check the settings:

$mail = new PHPMailer(true);

$mail->IsSMTP();

try{
    $mail->Host = "smtp.seudominio.com.br";
    $mail->SMTPAuth = true;
    $mail->Port     = 587;
    $mail->Username = "[email protected]";
    $mail->Password = "Senha";

    $mail->CharSet = 'UTF-8';

    //remetente
    $mail->SetFrom("[email protected]", "Nome Empresa");
    $mail->AddReplyTo("[email protected]", "Nome Empresa");
    $mail->Subject = "Um assunto";

    //destinatários
    $mail->AddAddress($this->emailDestinatario, "nome destinatário");
    $mail->AddCC($this->emailCopia, "Cópia pra fulano");

    $conteudo = "-- Dados --<br/>";

    //corpo do e-mail
    $mail->MsgHTML($conteudo);

    $mail->Send();

    return true;

}catch(phpmailerException $e){
    echo $e->errorMessage();
    return false;
}
    
06.12.2017 / 10:07