Contact.php from Template is failing to process and send email.

I have one of those dreaded TM templates which looks great, but the ‘contact’ part of the website does not work. Their tech support is frankly, pants. I can fill out the 4 fields and it recognises the data and will give a correct ‘message sent / message failed’ result but the data is never recieved in my inbox.
I have confirmed my server is php valid as I’ve done a simple test php.

I think the problem lies with the first few lines of code where the data is captured by the ‘contact.php’ script.

the 'Contact.php :
[php]

<?php //-----------------Getting data sent by flash--------------------- foreach($_POST as $key=>$value){ if ($key != 'mail_to' && $key != 'smtp_server' && $key != 'smtp_port' && $key != 'mail_from' && $key != 'mail_subject' && $key != 'plain_text'){ $mail_body .= ''.str_replace('_',' ',$key).':
'; $mail_body .= ''.stripslashes($value).'
'; }} //----------------------------------------------------------------- $message = ''.$mail_body.''; // mail body //------------if plain text is set to true removing html tags------ if ($_POST['plain_text']=='true') { $message = str_replace('
',"\r\n", $message); $message = strip_tags($message); //------------------------------------------------------------------ } else { //----otherwise composing message headers--------------------------- $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //------------------------------------------------------------------ } //------------setting conf data------------------------------------- $to = $_POST['mail_to']; $from = $_POST['mail_from']; $subject = $_POST['mail_subject']; $smtp_server = $_POST['smtp_server']; $smtp_port = $_POST['smtp_port']; //------------------------------------------------------------------ //---------setting header info------------------------------[code][/code]-------- $headers .= 'To: '.$to. "\r\n"; $headers .= 'From: Site visitor ' .$from. "\r\n"; //------------------------------------------------------------------ if (mail ($to, $subject, $message, $headers)) { // sending mail print('&mail=1'); //succes } else { print('&mail=0');//failure } ?>[/php]

The config file:

[code]<?xml version="1.0" encoding="utf-8"?>

[email protected] php contact true false Message sent. Message failed.....Please re-enter your details or send an email. processing... localhost 25 false 2 WebsiteVisitor <!-- Validation error messages that are showing to the user when the form fails to validate. The form supports different types of validators. You can change the text of the error messages the validators produce here.
    	You can use the {LABEL} keyword in these messages. It will replace it with the
    	label value of the field where an error occurs.
  -->
<validationErrorMessages>
    <!--
	    	A required field is not filled in.
	  -->
    <message type="fieldIsRequired">{LABEL} is required.</message>
    <!--	
	    	The specified e-mail address is incorrect.
	  -->
    <message type="emailNotValid">{LABEL} - is not valid email address.</message>
    <!--
	    	The specified number of characters in a field is less than a required minimum.
	  -->
    <message type="minCharsLimitError">{LABEL} - The specified number of characters in a field is less than a required minimum.</message>
    <!--
	    	The specified string does not match with the regular expression.
	  -->
    <message type="reqExpError">{LABEL} - The specified string does not match with the regular expression.</message>
    <!--
	    	The specified number is greater than an acceptable biggest number for this field.
	  -->
    <message type="biggerThanMaxError">{LABEL} - The specified number is greater than an acceptable biggest number for this field.</message>
    <!--
	    	The specified number is lower than an acceptable lowest number for this field.
	  -->
    <message type="lowerThanMinError">{LABEL} - The specified number is lower than an acceptable lowest number for this field.</message>
    <!--
	    	The data is not a number.
	  -->
    <message type="notANumberError">{LABEL} - The data is not a number.</message>
    <!--
	    	The specified number must not be negative.
	  -->
    <message type="negativeError">{LABEL} - The specified number must not be negative.</message>
    <!--
	    	The minimum number of variants is not selected
	  -->
    <message type="minRequirementError">{LABEL} - The minimum number of variants is not selected</message>
    <!--
	    	The number of variants selected exceeds the maximum
	  -->
    <message type="maxRequirementError">{LABEL} - The number of variants selected exceeds the maximum</message>
    <!--
	    	The fields that should be equal do not match
	  -->
    <message type="shouldBeEqualError">{LABEL} - values do not match</message>
    <!--
	     	The date has wrong format.
	  -->
    <message type="dateIsNotValidError">{LABEL} - date has wrong format</message>
</validationErrorMessages>

[/code]

and the structure file:

[code]<?xml version="1.0" encoding="utf-8"?>

<formItems>

	<item id="1" label="Name" required="true">
		<textToShow>NAME:</textToShow>
	</item>

	<item id="3" label="Tel">
		<textToShow>PHONE:</textToShow> 
				<restrict>+-.0-9</restrict>
	</item>

	<item id="2" label="E-mail" required="true">
		<textToShow>E-MAIL:</textToShow>
		<validator>EmailValidator</validator>
	</item>

	<item id="4" label="Message" required="true">
		<textToShow>MESSAGE:</textToShow>
	</item>

</formItems>

[/code]

I’ve checked through this and the error is certainly on the ‘Contact.php’… can anyone help ?

Keep in mind that with mail(), it returns TRUE or FALSE only for the message being accepted for delivery… not wether it’s received or not.

That being the case, have you echo’d out the $to value to make sure it’s a valid address? Other than that… the code looks to be OK, all the headers are there for HTML mail. Any chance it’s ending up in a spam trap?

The smtp variables are a little odd though… as far as I understand, you can’t pass that information to the mail function (gets it from php.ini) but it doesn’t look like it’s actually using them.

shrugs

I’ve now narrowed it down to the " if (mail($to… " etc section. These appear to be collecting the wrong data / not finding any data to send, Thus, not sending out anything.
I’ve checked my spam filters and even added my @domain to trusted emails.
Don’t laugh, but I’ve been hammering the keyboard for over 5 days on this… but I feel the end is near.

Stu

lol… we’ve all been there!

Try stripping out all the uncesseary:

[php]
//Comment all this out for now
/*
if (mail ($to, $subject, $message, $headers)) { // sending mail

print('&mail=1');  //succes

} else {

print('&mail=0');//failure

}*/
// add static values for everything, leave out $headers too
var_dump(‘[email protected]’, ‘test’, ‘test body’);
[/php]

See what var_dump returns and if you get the email…

No email arrived… :frowning:

OK… after a new approach, I’ve sorted and renamed most of the $strings and I’m now getting the correct info from my 4 fields. However, and this is the quirky bit… I’m getting an email through… but on a different domain from the one used in the script. The domain it arrives from is one of mine on my server (I have 12 domains) but at NO point did I use this email address in any of the code… Spooky odd.

Example:

Email arrives From: [email protected]

Used in script [email protected]

Can anyone explain that ?

Stu

Sponsor our Newsletter | Privacy Policy | Terms of Service