Jump to content

[SOLVED] PHP doesn't send my mail


Mr_J

Recommended Posts

Hi all, I found this and used it to send mail. Simple contact form with some required fields. The validation works a bit but I don't get the mail  :wtf:

HTML:some Javascript...

<form method=post enctype=multipart/form-data action=processor.php onSubmit="return validatePage1();"><ul class=mainForm id="mainForm_1">                           
                           
			<li class="mainForm" id="fieldBox_1">                           
				<label class="formFieldQuestion"><a name="form">N</a>ame * <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Please identify yourself</span></a></label><input class=mainForm type=text name=field_1 id=field_1 size='40' value='Name & Surname'></li>                                       
                                       
			<li class="mainForm" id="fieldBox_2">                                       
				<label class="formFieldQuestion">E-mail * <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Please enter a valid e-mail address</span></a></label><input class=mainForm type=email name=field_2 id=field_2 size=40 value="E-mail" style="background-image: url('imgs/email.png'); background-repeat: no-repeat; padding-left: 25px; padding-right: 2px; padding-top: 2px; padding-bottom: 2px"></li>                                       
                                       
			<li class="mainForm" id="fieldBox_3">                                       
				<label class="formFieldQuestion">Website <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Optional! Please enter your web address if available</span></a></label><input class=mainForm type=website name=field_3 id=field_3 size=40 value="Web address" style="background-image: url('imgs/website.png'); background-repeat: no-repeat; padding-left: 25px; padding-right: 2px; padding-top: 2px; padding-bottom: 2px"></li>                                       
                                       
			<li class="mainForm" id="fieldBox_4">                                       
				<label class="formFieldQuestion">Tel no <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Optional! Contact tel. no.</span></a></label><input class=mainForm type=phone name=field_4 id=field_4 size=40 value="Tel no" style="background-image: url('imgs/phone.png'); background-repeat: no-repeat; padding-left: 25px; padding-right: 2px; padding-top: 2px; padding-bottom: 2px"></li>                                       
                                       
			<li class="mainForm" id="fieldBox_5">                                       
				<label class="formFieldQuestion">Message * <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Please enter a short description of the nature of your business or what you want to advertise</span></a></label><textarea class=mainForm  name=field_5 id=field_5 rows=5 cols=40>Your message here</textarea></li>                                       
                                       
			<li class="mainForm" id="fieldBox_6">                                       
				<label class="formFieldQuestion">Terms of Service * <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>You MUST agree to our Terms of Service//Conditions before commencing</span></a></label><span><input class=mainForm type=checkbox name=field_6[] id=field_6_option_1 value="Do not Agree" /><label class=formFieldOption for="field_6_option_1">Do not Agree</label><input class=mainForm type=checkbox name=field_6[] id=field_6_option_2 value="Agree " /><label class=formFieldOption for="field_6_option_2">Agree </label></span></li>

 

The form use "PROCESSOR.PHP"

 

<?php

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

// Checkbox handling
$field_6_opts = $_POST['field_6'][0].",". $_POST['field_6'][1];

mail("[email protected]","Subject","Form data:

Name: " . $_POST['field_1'] . " 
E-mail: " . $_POST['field_2'] . " 
Website: " . $_POST['field_3'] . " 
Tel no: " . $_POST['field_4'] . " 
Message: " . $_POST['field_5'] . " 
Terms of Service: $field_6_opts
");

include("confirm.html");

?>

 

and confirm.html

 

<title>Conformation</title>
	<!-- calendar stuff -->
	      <link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" />
	      <script type="text/javascript" src="calendar/calendar.js"></script>
	      <script type="text/javascript" src="calendar/calendar-en.js"></script>
	      <script type="text/javascript" src="calendar/calendar-setup.js"></script>
	<!-- END calendar stuff -->

    <!-- expand/collapse function -->
    <SCRIPT type=text/javascript>
	<!--
	function collapseElem(obj)
	{
		var el = document.getElementById(obj);
		el.style.display = 'none';
	}


	function expandElem(obj)
	{
		var el = document.getElementById(obj);
		el.style.display = '';
	}


	//-->
	</SCRIPT>
	<!-- expand/collapse function -->


	<!-- expand/collapse function -->
	    <SCRIPT type=text/javascript>
		<!--

		// collapse all elements, except the first one
		function collapseAll()
		{
			var numFormPages = 1;

			for(i=2; i <= numFormPages; i++)
			{
				currPageId = ('mainForm_' + i);
				collapseElem(currPageId);
			}
		}


		//-->
		</SCRIPT>
	<!-- expand/collapse function -->


	 <!-- validate -->
	<SCRIPT type=text/javascript>
	<!--
		function validateField(fieldId, fieldBoxId, fieldType, required)
		{
			fieldBox = document.getElementById(fieldBoxId);
			fieldObj = document.getElementById(fieldId);

			if(fieldType == 'text'  ||  fieldType == 'textarea'  ||  fieldType == 'password'  ||  fieldType == 'file'  ||  fieldType == 'phone'  || fieldType == 'website')
			{	
				if(required == 1 && fieldObj.value == '')
				{
					fieldObj.setAttribute("class","mainFormError");
					fieldObj.setAttribute("className","mainFormError");
					fieldObj.focus();
					return false;					
				}

			}


			else if(fieldType == 'menu'  || fieldType == 'country'  || fieldType == 'state')
			{	
				if(required == 1 && fieldObj.selectedIndex == 0)
				{				
					fieldObj.setAttribute("class","mainFormError");
					fieldObj.setAttribute("className","mainFormError");
					fieldObj.focus();
					return false;					
				}

			}


			else if(fieldType == 'email')
			{	
				if((required == 1 && fieldObj.value=='')  ||  (fieldObj.value!=''  && !validate_email(fieldObj.value)))
				{				
					fieldObj.setAttribute("class","mainFormError");
					fieldObj.setAttribute("className","mainFormError");
					fieldObj.focus();
					return false;					
				}

			}



		}

		function validate_email(emailStr)
		{		
			apos=emailStr.indexOf("@");
			dotpos=emailStr.lastIndexOf(".");

			if (apos<1||dotpos-apos<2) 
			{
				return false;
			}
			else
			{
				return true;
			}
		}


		function validateDate(fieldId, fieldBoxId, fieldType, required,  minDateStr, maxDateStr)
		{
			retValue = true;

			fieldBox = document.getElementById(fieldBoxId);
			fieldObj = document.getElementById(fieldId);	
			dateStr = fieldObj.value;


			if(required == 0  && dateStr == '')
			{
				return true;
			}


			if(dateStr.charAt(2) != '/'  || dateStr.charAt(5) != '/' || dateStr.length != 10)
			{
				retValue = false;
			}	

			else	// format's okay; check max, min
			{
				currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30  + parseInt(dateStr.substr(6,4),10)*365;
				//alert(currDays);

				if(maxDateStr != '')
				{
					maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30  + parseInt(maxDateStr.substr(6,4),10)*365;
					//alert(maxDays);
					if(currDays > maxDays)
						retValue = false;
				}

				if(minDateStr != '')
				{
					minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30  + parseInt(minDateStr.substr(6,4),10)*365;
					//alert(minDays);
					if(currDays < minDays)
						retValue = false;
				}
			}

			if(retValue == false)
			{
				fieldObj.setAttribute("class","mainFormError");
				fieldObj.setAttribute("className","mainFormError");
				fieldObj.focus();
				return false;
			}
		}
	//-->
	</SCRIPT>
	<!-- end validate -->




</head>

<body onLoad="collapseAll()">

<div id="mainForm">




	<div id="formHeader">
			<h2 class="formInfo" align="center">Thank you!</h2>
			<p class="formInfo"> </p>
	</div>


	<BR/><ul class=mainForm><li class=mainForm>
            <p align="center"><label class=formFieldQuestion>We will contact you soon<a href="Javascript:window.close()"><BR/><BR/><input type="Button" value="Close Window"></a>
	<BR/></label></li></ul><BR/></div>
		<div id="footer">
			<p class="footer">
                    <a href="mailto:[email protected]" target="_blank"><img border="0" src="img/1.png" width="59" height="30" alt="Contact the Webmaster" title="Contact the Webmaster" align="middle" /></a>
        <a href="pp.html" target="_blank">Terms &amp Conditions</a>
</p></div>

</body>
</html>

 

and for what it's worth, the validation (JavaScript)

 

<!-- validate -->
        <SCRIPT type=text/javascript>
        <!--
            function validateField(fieldId, fieldBoxId, fieldType, required)
            {
                fieldBox = document.getElementById(fieldBoxId);
                fieldObj = document.getElementById(fieldId);

                if(fieldType == 'text'  ||  fieldType == 'textarea'  ||  fieldType == 'password'  ||  fieldType == 'file'  ||  fieldType == 'phone'  || fieldType == 'website')
                {   
                    if(required == 1 && fieldObj.value == '')
                    {
                        fieldObj.setAttribute("class","mainFormError");
                        fieldObj.setAttribute("className","mainFormError");
                        fieldObj.focus();
                        return false;                   
                    }

                }


                else if(fieldType == 'menu'  || fieldType == 'country'  || fieldType == 'state')
                {   
                    if(required == 1 && fieldObj.selectedIndex == 0)
                    {               
                        fieldObj.setAttribute("class","mainFormError");
                        fieldObj.setAttribute("className","mainFormError");
                        fieldObj.focus();
                        return false;                   
                    }

                }


                else if(fieldType == 'email')
                {   
                    if((required == 1 && fieldObj.value=='')  ||  (fieldObj.value!=''  && !validate_email(fieldObj.value)))
                    {               
                        fieldObj.setAttribute("class","mainFormError");
                        fieldObj.setAttribute("className","mainFormError");
                        fieldObj.focus();
                        return false;                   
                    }

                }



            }

            function validate_email(emailStr)
            {       
                apos=emailStr.indexOf("@");
                dotpos=emailStr.lastIndexOf(".");

                if (apos<1||dotpos-apos<2) 
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }


            function validateDate(fieldId, fieldBoxId, fieldType, required,  minDateStr, maxDateStr)
            {
                retValue = true;

                fieldBox = document.getElementById(fieldBoxId);
                fieldObj = document.getElementById(fieldId);    
                dateStr = fieldObj.value;


                if(required == 0  && dateStr == '')
                {
                    return true;
                }


                if(dateStr.charAt(2) != '/'  || dateStr.charAt(5) != '/' || dateStr.length != 10)
                {
                    retValue = false;
                }   

                else    // format's okay; check max, min
                {
                    currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30  + parseInt(dateStr.substr(6,4),10)*365;
                    //alert(currDays);

                    if(maxDateStr != '')
                    {
                        maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30  + parseInt(maxDateStr.substr(6,4),10)*365;
                        //alert(maxDays);
                        if(currDays > maxDays)
                            retValue = false;
                    }

                    if(minDateStr != '')
                    {
                        minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30  + parseInt(minDateStr.substr(6,4),10)*365;
                        //alert(minDays);
                        if(currDays < minDays)
                            retValue = false;
                    }
                }

                if(retValue == false)
                {
                    fieldObj.setAttribute("class","mainFormError");
                    fieldObj.setAttribute("className","mainFormError");
                    fieldObj.focus();
                    return false;
                }
            }
        //-->
        </SCRIPT>
        <!-- end validate -->

 

:shrug:

Link to comment
https://forums.phpfreaks.com/topic/178218-solved-php-doesnt-send-my-mail/
Share on other sites

Do you have error reporting turned on?

Good idea ;), will switch it on...

Have you checked your 'Junk Mail' folder?

Yes, no mail!!

Are you running it on localhost or a live remote server?

Live remote server, I have apache installed on vista but this is on my live server...

Does the contents of confirm.html appear on screen?

confirm.html = perfect incl. my window.close() function...

 

The mail function returns true or false based on if it sent successfully so it's worth checking what it returns (note that the value yes doesn't mean the user recieved it, only that it successfully sent). Obviously error reporting may give you some more information. One thing worth trying is using php_info() and checking the SMTP settings for your server are setup correctly. Another thing worth doing is using $headers = "From: [email protected]\r\n"; as your 4th parameter.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.