0

the following script i believe is 100% correct but mail isn't sent, or at least isn't reaching my mailbox.

I've checked spam foldes.

WWW DNS is pointed to another host, i'm using its temp URL to test, but mail is still local in this hosting.

http://paulinhomotos1.hospedagemdesites.ws/exemplo/form/form.html

HTML:

<html>
<head>
<script language="javascript" type="text/javascript">
function checa_formulario(email){
if (email.nome.value == ""){
alert("Por Favor não deixe o seu nome em branco!!!");
email.nome.focus();
return (false);
}
if (email.email_from.value == ""){
alert("Por Favor não deixe o seu email em branco!!!");
email.email_from.focus();
return (false);
}
if (email.email.value == ""){
alert("não deixe o email destinatario em branco!!!");
email.email.focus();
return (false);
}
if (email.assunto.value == ""){
alert("não deixe o assunto em branco!!!");
email.assunto.focus();
return (false); 
}   
}
</script>
<title>Enviando texto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
</head>
<body onLoad="document.email.nome.focus();">
<form onSubmit="return checa_formulario(this)" action="mail.php" method="post" enctype="multipart/form-data" name="email">
<table width="32%" border="0" align="center">
<tr>
<td><div align="right"><span class="texto">Name</span></div></td>
<td><input name="nome" type="text" id="nome"></td>
</tr>
<tr>
<td width="33%"><div align="right" class="texto">E-Mail</div></td>
<td width="67%"><input name="email_from" type="text" class="email"></td>
</tr>
<tr>
<td><div align="right" class="texto"></div></td>
</tr>
<tr>
<td><div align="right" class="texto">Subject</div></td>
<td><input name="assunto" type="text" id="assunto"></td>
</tr>
<tr>
<td><div align="right" class="texto">Message</div></td>
<td><textarea name="mensagem" cols="50" rows="10" id="mensagem"></textarea></td>
</tr>
<tr>
<td><div align="right" class="texto">Attachment</div></td>
<td><input name="arquivo" type="file"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Enviar"></td>
</tr>
</table>
</form>
</body>
</html>

PHP:

<?php
//pego os dados enviados pelo formulario
$nome = $_POST["nome"];
$email = "visualexpert@gmail.com";
$mensagem = $_POST["mensagem"];
$assunto = $_POST["assunto"];
$email_from = $_POST["email_from"];
//formato o campo da mensagem
$mensagem = wordwrap( $mensagem, 50, "
", 1);
//valido os emails
if (!ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$", $email)){
echo"<center>Digite um email valido</center>";
echo "<center><a href=\"java script:history.go(-1)\">Voltar</center></a>";
exit;
}
if (!ereg("^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$", $email_from)){
echo "<center>Digite um email valido</center>";
echo "<center><a href=\"java script:history.go(-1)\"><center>Voltar</center></a>";
exit;
}
$arquivo = isset($_FILES["arquivo"]) ? $_FILES["arquivo"] : FALSE;
if(file_exists($arquivo["tmp_name"]) and !empty($arquivo)){
$fp = fopen($_FILES["arquivo"]["tmp_name"],"rb");
$anexo = fread($fp,filesize($_FILES["arquivo"]["tmp_name"]));
$anexo = base64_encode($anexo);
fclose($fp);
$anexo = chunk_split($anexo);
$boundary = "XYZ-" . date("dmYis") . "-ZYX";
$mens = "--$boundary\n";
$mens .= "Content-Transfer-Encoding: 8bits\n";
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n\n"; //plain
$mens .= "$mensagem\n";
$mens .= "--$boundary\n";
$mens .= "Content-Type: ".$arquivo["type"]."\n";
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"\n";
$mens .= "Content-Transfer-Encoding: base64\n\n";
$mens .= "$anexo\n";
$mens .= "--$boundary--\r\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "From: \"$nome\" <$email_from>\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$headers .= "$boundary\n";
//envio o email com o anexo
mail($email,$assunto,$mens,$headers);
echo"Email enviado com Sucesso!";
}
//se não tiver anexo
else{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: \"$nome\" <$email_from>\r\n";
//envia o email sem anexo
mail($email,$assunto,$mensagem, $headers);
echo"Email enviado com Sucesso!";
}
?>

Thanks.

  • Have you checked the maillog on the server? First place you should start when trying to debug this. It should show it being accepted and then give an indication of whether it was able to deliver it . – Neddage Aug 13 '15 at 14:56
  • With regards to your use of ereg function: "This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged." – Professor Abronsius Aug 13 '15 at 15:10
  • Hey @neddage, any clues on how can I do that? thanks. – Guilherme Santos Aug 13 '15 at 17:06
  • @RamRaider oh didn't know that. I will remove that validation from php and make it javascript in html. Thanks. – Guilherme Santos Aug 13 '15 at 17:06
  • If it is a linux server it is normal in /var/log/maillog if its not a linux server, I have no idea where the logs are stored. – Neddage Aug 13 '15 at 17:11

0 Answers0