0
I am developing a website with contact form. The form
is very simple only with name, email, message and subject fields.
I have the site hosted on a server, but I need the data from form
are received in an email account on another server, not what is configured in the hosting service.
I tried for the php mail function and it didn’t work, I tried using the Phpmailer class and there was an error related to STMP: (SMTP Error: Could not connect to SMTP host. Could not send message. Error: SMTP Error: Could not connect to SMTP host.)
Made the following mistake:
Parse error: syntax error, Unexpected end of file in /home/trweb146/public_html/desenvolvimento/Formemailphpmailer/enviar.php on line 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?
I’ve been there, in my case it was because the email I was using to send should be one of the hosting. For example, you have to create an email@your domain.comand use it to send.
– Jhonatan Pereira
"The sender must be an email from your domain as determined by RFC 822.". As for SMTP, which even you can only send e-mail to Outlook and Cia. using it, probably your host is smtp.dominio.com.br.
– Jhonatan Pereira
Jhonatan Pereira - I have no way to use emails from the same site hosting, the emails are in a hosting outside the site server.
– TRWEBSITES
Jhonatan Pereira - I don’t understand, you said that "As for SMTP, which even you can only send email to Outlook and Cia.", I can’t send emails to an Hostgator account for example? If yes, which configuration should I use you can tell me?
– TRWEBSITES
You don’t understand. Let’s say you have to send email to [email protected]. To send them you have to send some email (the sender). The sender may have to be an email from the hosted domain, only your hosting can confirm. Update the question and Put your code, it’s easier to help.
– Jhonatan Pereira
Microsoft Outlook, Hotmail, MSN and etc only receive email if it is by SMTP. Sending using the mail() function the recipient does not receive. Not that SMTP only send to these, it sends to all mail servers.
– Jhonatan Pereira
The error you showed (Unexpected end of file) indicates that it has some character that was opened but not closed. It can be quotes, keys, something like that. In the code that showed no error, I was line 61, check next to her
– Jhonatan Pereira
Or 61 is the last line of the file because it encountered an unexpected ending. Are you using any code editor? Bracket Editor makes it easy to find these problems.
– Jhonatan Pereira
Exchange the
<?
for<?php
, this is a syntax error because your server has disabled PHP short_tags, more details on https://answall.com/a/51003/3635 (look for the section I’m talking aboutMisturar tags PHP (<?php) com short_open_tag (<?)
)– Guilherme Nascimento