/    Sign up×
Community /Pin to ProfileBookmark

My first PHP script – it doesnt work and I cant see why! (by all accounts it should!)

Hi,

I’m needing a little help with this bit of PHP code. I’m new to this and this is my first attempt. When I submit the form on the website it gives me the successful message (form data etc successfully sent to myemail@somehost etc), but the information/email never, ever arrives. I’m sending it to my own email address, which is not Hotmail, Yahoo etc. Can someone take a knowing look at it and possibly tell me where I’m going wrong? ? Its only a basic form consisting of four data fields…?

Below is my PHP script I have placed on the server. Please help!

[code=php]
<?php
// setup php basic configuration
$email_to = ‘[email protected]’;
$subject = ‘website enquiry’;
//receive variables from contact mail_form
$Contact_Name = $_POST[‘Contact_Name’];
$Contact_Number = $_POST[‘Contact_Number’];

if ($Contact_Number == NULL){
$dont_send = true;
} else {
$dont_send = false;
}
$Contact_email = $_POST[‘Contact_email’];
$customer_enquiry = $_POST[‘customer_enquiry’];

$messafe = “Name: ” . $Contact_Name . “n”;
$messafe .= “Number: ” . $Contact_Number . “nn”;
$messafe .= “Email: ” . $Contact_email . “nn”;
$messafe .= “Enquiry: ” . $customer_enquiry . “nn”;

?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>

<?php echo $Contact_Name.”,br/>”.$Contact_Number.”,br/>”.$Contact_email.”,br/>”.$customer_enquiry.”,br/>” ;
?>
<?php

if ($dont_send == false){

if ( mail($email_to , $subject , $message ) ) {
echo “Email successfully sent to ” . $email_to ;

} else {
echo “Email failed to send”;

}

} else {
echo “Please Fill in your Contact Number” ;
}
?>
</body
></body>
</html>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@sstalderApr 21.2008 — May want to get in touch with the tech support for your host. Sometimes hosts will disable the mail function for security reasons.

You can also try:

mail('[email protected]','test','test');

Just to see if it actually sends a very simple email.
Copy linkTweet thisAlerts:
@JonnoVisionauthorApr 21.2008 — May want to get in touch with the tech support for your host. Sometimes hosts will disable the mail function for security reasons.

QUOTE]

Hi, thanks for the reply. I emailed them and their response was that it must be something to do with my script. However, I looked at the server options for my hosting and noted the following :

My current website is hosted on a windows based server, and noted Static - it says "This website will be hosted on a server designed for static webpages.

PHP and Perl scripts will run; however, you should choose the Dynamic website server option below for improved performance if you intend to use scripts."

The alternative is to host the website on a windows platform still but as a dynamic website, the host info saying "This website will be hosted on a server designed specifically for using scripts.

Include ASP, PHP, Perl, compiled CGI, ISAPI and SHTML scripting.

You should also choose this option if you intend to use Microsoft FrontPage Extensions. "

Would this really make any difference? and I'm not using Microsoft Frontpage:p Dreamweaver all the way...

What concerns me is that I cant see why the script wont run as it current stands. Any more advice would be great, and thank you for your post ?
Copy linkTweet thisAlerts:
@JonnoVisionauthorApr 21.2008 — In addition, the hosting people said this "It sounds like the mail sending method is incorrect. You can use sendmail on linux but not on windows as it is a linux only method. If on a windows server you will need to use jmail or CDONTS." - Not sure what this means though...?
Copy linkTweet thisAlerts:
@esmApr 22.2008 — I'll let you address the issue of whether or not your host allows you to send it.

as for the code itself: the br/> should be [B][COLOR="Red"]<[/COLOR][/B]br/>

you are using $_POST variables, but you have no form...!!!

at least one of the variables did not match up: $messafe vs $message.

that should get you started.

there are lots of tutorials out there. wouldn't hurt to study them.


.
Copy linkTweet thisAlerts:
@JonnoVisionauthorApr 23.2008 — 
you are using $_POST variables, but you have no form...!!!

.[/QUOTE]


Yes sorry, I didnt post my HTML side, here it is [code=html] <form id="form1" method="post" action="email_script.php">
<table width="420" height="397" border="0">
<tr>
<td width="210"><span class="Headings">Name</span></td>
<td width="210"><label>
<div align="left">
<input type="text" name="Contact_Name" id="Contact_Name" />
</div>
</label></td>
</tr>
<tr>
<td><span class="Headings">Contact Number</span></td>
<td><label>
<div align="left">
<input type="text" name="Contact_Number" id="Contact_Number" />
</div>
</label></td>
</tr>
<tr>
<td><span class="Headings">Email</span></td>
<td><label>
<div align="left">
<input type="text" name="Contact_email" id="Contact_email" />
</div>
</label></td>
</tr>
<tr>
<td><span class="Headings">Enquiry</span></td>
<td><label>
<textarea name="customer_enquiry" cols="50" rows="5" id="customer_enquiry">Please enter your enquiry here</textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<label>
<input type="submit" name="Send_mail" id="Send_mail" value="Submit" />
</label>
</div></td>
</tr>
</table>
</form>[/code]


Thanks for spotting those silly mistakes, I didnt see them myself! I'm sorry if my queries sound amateur, but I am just starting out on using PHP/coding so its all new to me. I've looked at the host details and apparently I think the problem could be that with this host, the form has to be sent 'from' an email address on my server, so I think I have to somehow automate that process within the php script to send the form information from a hosted email account within my domain, to the receiving email account within my domain - does this make sense? Sounds a bit strange to me, so I am looking online for tutorials for this, so thanks all for your input to date.
×

Success!

Help @JonnoVision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...