I am new to most the web programming experience and I have a php page (lets call it form.php for brevity) that posts some form information (including an attachment) to another php file that validates organizes the information (which I will call sendMail.php) and then mails it to the destination. When I try to send on Firefox the page will redirect to back to form.php with the message that the email was sent. It was only in IE that I saw the page redirection fail. That's when I opened fire bug an noticed the Failed to load source for: http://www.../sendMail.php
I am in a pickle and need to finish this site and have beat my head to what causes this. I will include samples and url for the web ninja masters to look at my dirty laundry. The problem page is here.
One thing to note is the same sendMail.php handles a different comment form with out problems - link to working page.
For sendMail.php which is very much a WIP:
<?php
require_once('class.phpmailer.php');//include ("smtp.class.php");
$host = "########"; /*host do servidor SMTP */
$mail = "########@######";//o endere�o de e-mail deve ser v�lido.
$senha = "#######";
$newLine = "\r\n";
$testEmail = "#########@####.com";
$acceptedExtensions = array('doc', 'docx', 'pdf');
/* All form fields are automatically passed to the PHP script through the array $_POST. */
$name = $_POST['name'];
$email = $_POST['email'];
$presub = $_POST['subject'];
$message = $_POST['message'];
$page = $_POST['page'];
// setting up the body of the message
$emailbody = '<html><head></head><body>';
$fileExist = false;
//validating information and combining for message body
if(isset($_POST['nome'])){
$name = $_POST['nome'];
$emailbody .= "Nome: " . $name . $newline . '<br />';
}
if(isset($_POST['endereco']) && !empty($_POST['endereco'])){
$address = "Endereco: " . $_POST['endereco'] . $newline . '<br />';
$emailbody .= $address;
}
if(isset($_POST['bairro']) && !empty($_POST['bairro'])){
$neighborhood = "Bairro: " . $_POST['bairro'] . $newline . '<br />';
$emailbody .= $neighborhood;
}
if(isset($_POST['cidade']) && !empty($_POST['cidade'])){
$city = "Cidade: " . $_POST['cidade'] . $newline . '<br />';
$emailbody .= $city;
}
if(isset($_POST['estado']) && !empty($_POST['estado'])){
$state = "Estado: " . $_POST['estado'] . $newline . '<br />';
$emailbody .= $state;
}
if(isset($_POST['telefone']) && !empty($_POST['telefone'])){
$telephone = "Telefone: " . $_POST['telefone']. $newline . '<br />';
$emailbody .= $telephone;
}
if(isset($_POST['celular']) && !empty($_POST['celular'])){
$cel = "Celular: " . $_POST['celular'] . $newline . '<br />';
$emailbody .= $cel;
}
if(isset($_POST['email']) && !empty($_POST['email'])){
$email = "E-mail: " . $_POST['email'] . '<br />';
$emailbody .= $email;
}
if(isset($_POST['subject']) && !empty($_POST['subject'])){
$sub = $_POST['subject'];
$emailbody .= "Assunto: " . $_POST['subject'] . '<br />';
}
if(isset($_POST['message']) && !empty($_POST['message'])){
$email = "<br />Mensagem: <br /><br />" . $_POST['message'] . '<br />';
$emailbody .= $email;
}
if(isset($_FILES['anexo'])){
if($_FILES['anexo']['name'] !== "") { // &&
$fileExist = true;
uploadFile();}
}
if ($presub == 'd�vida'){
$sub = 'Duvida';
}elseif ($presub == 'sugest�o'){
$sub = 'Sugest�o';
}elseif ($presub == 'cr�tica'){
$sub = 'Critica';
}elseif ($presub == 'elogio'){
$sub = 'Elogio';
}else {
$sub = $presub;
}
$emailbody.= '</body></htm>';
//$emailbody = $name . $email . $address . $neighborhood . $city . $state . $telephone . $cel . $email . $sub . $message;
//to who the message will be sent
if ($page == "empresa_faleconosco"){
$goto = $testemail;
}elseif ($page == "empresa_trabalheconosco"){
$goto = $testemail; // "dpessoal@cda.med.br";
}elseif ($page == "secretarias_faleconosco"){
$goto = $testemail; // " marketing@cda.med.br";
}elseif ($page == "medicos_trabalheconosco"){
$goto = $testemail; // "dr.alessandroaguilar@gmail.com";
}/*elseif ($page == ""){
$goto = $testemail;
}*/
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "host"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "host"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP account username
$mail->Password = "password"; // SMTP account password
//$mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress($testEmail, 'Samuel Molinski');
$mail->SetFrom('webmarketing@cda.med.br', 'Web Marketing');
//$mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->Subject = $sub;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($emailbody);
//$mail->AddAttachment("uploads"."/".$_FILES['anexo']['name']);
if ($fileExist == true) {
if($_FILES['anexo']['name'] != ""){
if (validAttachment($_FILES['anexo'], 200, $acceptedExtensions)){
$mail->AddAttachment("uploads"."/".$_FILES['anexo']['name']); // attachment tmp_
}else{
echo "Attachment not sent. </p>\n";
}
}
}
$enviou = $mail->Send() ? 'enviou' : 'falhou';
//$mail->Send();
if($fileExist == true){
unlink("uploads"."/".$_FILES['anexo']['name']);
}
//echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
} catch (Exception $e) {
}
header("Location:$page.php?status=".$enviou);
function uploadFile() {
global $attachments;
//
$filename = $_FILES['anexo']['name'];
//the Array will be used later to attach the files and then remove them from server ! array_push($attachments, $filename);
$dir = "uploads/$filename";
//chmod("uploads",0777);
$success = copy($_FILES['anexo'][tmp_name], $dir);
/*//
if ($success) {
echo " Files Uploaded Successfully<BR>";
}else {
exit("Sorry the server was unable to upload the files...");
}
*/
}
//uploading files to email using the file name and length, with exceptable file type default size of ~3mb
function validAttachment($file, $length=300, $extensionsAllowed = null) {
$name_of_uploaded_file =
basename($_FILES['anexo']['name']);
//echo ($name_of_uploaded_file);
//get the file extension of the file
$type_of_uploaded_file =
substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
//echo ($type_of_uploaded_file);
$size_of_uploaded_file =
$_FILES['anexo']["size"]/1024;//size in KBs
//echo ($size_of_uploaded_file);
//Settings
$max_allowed_file_size = $length; // size in KB
$allowed_extensions = $extensionsAllowed;
//echo ($max_allowed_file_size);
//echo ($allowed_extensions);
//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
//echo ("\n Size of file should be less than $max_allowed_file_size");
return false;
}
//------ Validate the file extension -----
if ($extensionsAllowed == !null)
{
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++)
{ echo ($allowed_extensions[$i]);
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
//echo ("\n The uploaded file is not supported file type.");
$errors .= "\n The uploaded file is not supported file type. ".
" Only the following file types are supported: ".implode(',',$allowed_extensions);
return false;
} else
{
$allowed_ext = true;
}
}
return true;
}
?>
(sorry it that looks like spam; not sure how to make it smaller)
I have a stress reduction kit mounted on my wall and it's not working ;) I know sometime it just takes a second look. Thank ahead of time for your insight and help.