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:

	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
		$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($_FILES['anexo']['name'] !== "") { // && 
		$fileExist = true;
	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
	  if ($fileExist == true) {
		  if($_FILES['anexo']['name'] != ""){
		if (validAttachment($_FILES['anexo'], 200, $acceptedExtensions)){
			$mail->AddAttachment("uploads"."/".$_FILES['anexo']['name']);      // attachment  tmp_
			echo "Attachment not sent. </p>\n";
	  $enviou = $mail->Send() ? 'enviou' : 'falhou';
	  if($fileExist == true){
	  //echo "Message Sent OK</p>\n";
	} catch (phpmailerException $e) {
	} catch (Exception $e) {
	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";
	$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 =  
		//echo ($name_of_uploaded_file);
		//get the file extension of the file
		$type_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);
		$max_allowed_file_size = $length; // size in KB 
		$allowed_extensions = $extensionsAllowed;
		//echo ($max_allowed_file_size);
		//echo ($allowed_extensions);
		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;    
					  //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.

Recommended Answers

All 3 Replies

Don't think the error is in your sendMail.php file. There seems to be a problem with loading it. I did notice a difference in the form definition on the pages that work and don't work.

<!-- from the page that works -->
<form id="currentForm" method="post" action="sendMail.php" class="" style="padding-left: 30px; float: left;">
<!-- from the page that does not work  -->
<form id="currentForm" name="Oportunidades" action="sendMail.php" method="POST" enctype="multipart/form-data">

For both pages the url starts with http://www.cda.med.br/modelo/.
But when I type in http://www.cda.med.br/modelo/sendMail.php I get "The system cannot find the file specified." and the url shown is http://www.cda.med.br/modelo/.php?status=enviou.
If sendMail.php is in the right place it should at least be found.

Do you have any redirection active through a .htaccess file or in your apace configuration? That would explain why one page can find sendMail.php and the other can't.

commented: ++ +6

colweb - I reviewed your comment and have tried adjusting the form heading to match the other with no results.

the nature of sendMail.php is just to process the email and then update the page with the information of whether email was successful or not. sendMail.php will not work alone(can't type in a url and get a page) because it needs to take the posted info from a form and then redirect (line 148 returning the variable $enviou, "$sent" in Portuguese). Inside of the form.php is the small script to interpret this as sent, unsent and default. here is an example of the incomplete code (missing closing else "}" not displayed)

if(isset($_GET['status']) && $_GET['status'] == 'enviou') {
				<div class="emailsent">
					<p>Mensagem enviada com sucesso!</p>
}elseif(isset($_GET['status']) && $_GET['status'] == 'falhou'){
				<div class="emailfail" >
					<p>Falha não envio!</p>

the url http://www.cda.med.br/modelo/.php?status=enviou is produced if the page does not have a valid $page variable defined (line 15) by the <input name="page" value="empresa_trabalheconosco" type="hidden" /> in the forms giving the name of the form sending the info.

From the very little I have seen on the web about "failed to load source" is that it is just that, some file is not available or doesn't exist, but this doesn't help me find what is not loading. There is only one reference inside of sendMail.php and no HTML to speak of.

It is very possible that the way I have written the php file. Why does the page load for one form, process and send an email, but the other simple fail. I have checked the file structure and everything is there. Could it be a server setting that prevents the script from executing and throws the error? Maybe it is the "empresa_trabalheconosco.php" page that is ultimately flawed.

Thanks again.

I finally found the thorn in this little project. I am still not sure about the firebug error "failed to load source for:". I have my suspicious that i was the result of the php page redirecting and maybe not finishing parsing/executing(which ever it is) there for not loading.

The error was a bit of code in the forms that started to pay attention to after colweb called my attention to the different form headers. it was the addition of enctype="multipart/form-data" that was killing it in IE8.

thanks all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.