Best place to get a script for this form

Could anyone point me in the right direction regarding learning how to put a php script behind this form -
http://www.pauserefreshment.co.uk/coffee-machine-brochure-request.html

Basically I ant the info to be pinged back to my emial address.

Anyinsights welcome :slight_smile:

Validation and [URL=“http://en.wikipedia.org/wiki/E-mail_injection”]Injection issues aside Dave, try this:-


<?php
$configuration = array(
  'email.to'      => 'you@home.com',
  'email.from'    => 'you@home.com',
  'email.subject' => 'A website enquiry!'
);

if('POST' === $_SERVER['REQUEST_METHOD']){

  $message = sprintf(
    "
    This is a test message:-
      Name:   &#37;s %s
      Email:  %s
 
    Thanks.
    ",
    $_POST['name'],
    $_POST['secondname'],
    $_POST['email']
  );
  
  ini_set('sendmail_from', $configuration['email.from'])
 
  if(mail($configuration['email.to'], $configuration['email.subject'], $message, sprintf("%s\\r\
", $configuration['email.from']))){
    echo '<h1>Thankyou.</h1>';
    exit;
  }
 
}
?>
<h1>
 Sorry, an error occured.
</h1>

Make sure the email.from option is an email address registered at your domain. For example, if your domain was example.org, use no-reply@example.org.

Good luck!

Anthony.

Looks like my php form has imploded :frowning:

I just cant get it to pink back anything despite adding a sitepoint members
solution see below:

 <?php
$to = 'user@domain.com';
$subject = 'the subject';
$from = 'email@domain.com';
$message ='';

foreach($_POST as $name => $data)
{
  if(is_array($data))
  {
    foreach($data as $datum)
    $message .= $name . ": " . $datum . " \
";
  }
else
  $message .= $name . ": " . $data . " \
";
}

# Attempt to send email
if(mail($to, $subject, $message, "From: $from"))
  echo "Mail sent";
else
  echo "Mail send failure - message not sent";
?> 

Ive got an ugly feeling Ive bitten off more than I can chew. Thanks Mark Anthony for helping me but this form:
http://www.pauserefreshment.co.uk/coffee-machine-brochure-request.html
remains php dead :mad:

Looking at the code I have the disadvantage of knowing nothing about php which means I couldnt even figure out where to put my eMail address to get the info into my inbox.

I’m going back to the drawing board and taking a look at a tutorial in Head first php & My sql book see if i can get it. Seams a bit of a pain when all i want is for this form just to work…

Looking at the code I have the disadvantage of knowing nothing about php which means I couldnt even figure out where to put my eMail address to get the info into my inbox.

So you didn’t replace your email into the code?

<?php
$to = 'your_email_here@domain.com';
$subject = 'the subject';
$from = 'email_to_send_from@domain.com';
$message ='';

Just replace the values between the quotes (’ and ') with your email.

Heres some more detail to my problem (no more googling I need a sitepoint member to help me)


http://www.pauserefreshment.co.uk/coffee-machine-brochure-request.html

Hi from wakefiled UK, v hot & humid…

Ive never done php before & today I tried but failed to get a form to ping back data filled out on a form to my eMail . The form in question is the top url link and screen grab of the form.

I know I have to create a seperate php file and whilst at the mo this is empty. I cleared all previous efforts as they failed miserably I do at least understand it needs a php script behind the form but I’m out of my depth big time:-(

heres the code for the form:

<!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 name="ROBOTS" CONTENT="NOINDEX,NOFOLLOW" />
<meta  name="Description" CONTENT="Request postal delivery of a coffee machine brochure for your office, hotel or pub" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coffee machine brochure request form | pause... refreshment</title>
<link rel="stylesheet" type="text/css" href="css/brochure_form.css">
</head>
<body>
<form action="brochure.php" method="post">
  <h1>"Order a  brochure"</h1>
<fieldset>
    <div id="contact_details">
  <h2>Please enter your contact details</h2>
      <label for="name">First Name</label>
    <input type="text" name="name" id="name"/>
  </div>
  <div id="contact_details" >
    <label for="secondname">Second Name</label>
    <input type="text" name="secondname" id="secondname" />
  </div>
  <div id="contact_details">
    <label for="email">e Mail</label>
    <input type="text" name="email" id="email" />
  </div>
  <div id="contact_details">
    <label for="company">Company name</label>
    <input type="text" name="company" id="company"/>
  </div>
   <div id="contact_details">
    <label for="address">Address Line 1</label>
    <input type="text" name="address" id="address"/>
  </div>
  <div id="contact_details">
    <label for="address2">Address Line 2</label>
    <input type="text" name="address2" id="address2"/>
  </div>
  <div id="contact_details">
    <label for="postcode">Postcode</label>
    <input type="text" name="postcode" id="postcode"/>
  </div>
    <div id="brochure_pick">
    <h2>Select the brochure(s) you want posted</h2>
    <h3>Traditional & bean to cup<br/>
      "Ideal for restaurants and cafes"</h3>
    <label for="laspaziale">La Spaziale</label>
    <input type="checkbox" name="laspaziale" id="laspaziale"  />
    <label for="lacimbali">La Cimabli M1</label>
    <input type="checkbox" name="lacimbali" id="lacimbali"  />
     <label for="Koro">Koro</label>
    <input type="checkbox" name="koro" id="koro" />
    <label for="franke">Franke Flair</label>
    <input type="checkbox" name="franke" id="franke" />
    <h3>Instant<br/>
    "Ideal for offices"</h3>
  <div id="brochure_pick">
    <label for="vision400">Vision 400</label>
    <input type="checkbox" name="vision400" id="vision400" />
    <label for="darenth">Darenth</label>
    <input type="checkbox" name="darenth" id="darenth" />
  </div>
  <h3>Filter<br/>
    "Ideal for most set ups"</h3>
  <label for="mondo">Mondo</label>
  <input type="checkbox" name="mondo" id="mondo" />
  <label for="marco">Marco qwikbrew</label>
  <input type="checkbox" name="marco" id="marco" />
  </div>
    <div id="send">
    <input type="submit" value="Order Brochure">
  </div>
  </fieldset>
</form>
</body>
</html>

So my question is please…

"How do i begin to get a script to meake all entries ping back to me. Ive covered all sorts of tutorials but no luck :frowning:

Any insights welcome…

You want to create a script that receives the info from the form, and send an email? Googling gives you lots of tutorials that talk about just that. A good starting point, no?
Unless of course I misunderstood your question.

eh?

Problem fixed - thanks Ant for all your help no doubt i’ll need it again :slight_smile:

Basically this form -
http://www.pauserefreshment.co.uk/report.html
now works. The problem lied in SMTP authentication. Thank you again :slight_smile:

Resolved

Hi Ant…

Do you mean a semi colon is missing from the current php script which is now this:

<?php
$configuration = array( 
'email.to'      => 'david@pause.co.uk', 
'email.from'    => 'you@home.com', 
'email.subject' => 'A website enquiry!'
);

if('POST' === $_SERVER['REQUEST_METHOD']){ 

$message = sprintf(   
"   This is a test message:-     
Name:   %s %s     
Email:  %s   

Thanks.   
",   
$_POST['name'],   
$_POST['secondname'],   
$_POST['email']
);  

ini_set('sendmail_from', $configuration['email.from'])

if(mail($configuration['email.to'], $configuration['email.subject'], $message, sprintf("%s\\r\
", $configuration['email.from']))){   echo '<h1>Thankyou.</h1>';   exit;
}
 
}
?>
<h1>Sorry, an error occured.</h1>

Please let me know where the semi colon goes :slight_smile:

Right - forget everyhing previous in this post. All i need to know please is why when i fill out this form:
http://www.pauserefreshment.co.uk/report.html

I get this error message:
Warning: mail() [function.mail]: SMTP server response: 554 <hello@pause.co.uk>: Recipient address rejected: Relay access denied in E:\domains\p\pauserefreshment.co.uk\user\htdocs\report.php on line 29

php script:

<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>
<?php
  $name = $_POST['firstname'] . ' ' . $_POST['lastname'];
  $when_it_happened = $_POST['whenithappened'];
  $how_long = $_POST['howlong'];
  $how_many = $_POST['howmany'];
  $alien_description = $_POST['aliendescription'];
  $what_they_did = $_POST['whattheydid'];
  $fang_spotted = $_POST['fangspotted'];
  $email = $_POST['email'];
  $other = $_POST['other'];

  $to = 'hello@pause.co.uk';
  $subject = 'Aliens Abducted Me - Abduction Report';
  $msg = "$name was abducted $when_it_happened and was gone for $how_long.\
" .
    "Number of aliens: $how_many\
" .
    "Alien description: $alien_description\
" .
    "What they did: $what_they_did\
" .
    "Fang spotted: $fang_spotted\
" .
    "Other comments: $other";
  mail($to, $subject, $msg, 'From:' . $email);

  echo 'Thanks for submitting the form.<br />';
  echo 'You were abducted ' . $when_it_happened;
  echo ' and were gone for ' . $how_long . '<br />';
  echo 'Number of aliens: ' . $how_many . '<br />';
  echo 'Describe them: ' . $alien_description . '<br />';
  echo 'The aliens did this: ' . $what_they_did . '<br />';
  echo 'Was Fang there? ' . $fang_spotted . '<br />';
  echo 'Other comments: ' . $other . '<br />';
  echo 'Your email address is ' . $email;
?>
</body>
</html>

Any insights welcome

Sorry! My fault, it was missing a ;


<?php
$configuration = array(
  'email.to'      => 'you@home.com',
  'email.from'    => 'you@home.com',
  'email.subject' => 'A website enquiry!'
);

if('POST' === $_SERVER['REQUEST_METHOD']){

  $message = sprintf(
    "
    This is a test message:-
      Name:   &#37;s %s
      Email:  %s
 
    Thanks.
    ",
    $_POST['name'],
    $_POST['secondname'],
    $_POST['email']
  );
  
  ini_set('sendmail_from', $configuration['email.from']);
 
  if(mail($configuration['email.to'], $configuration['email.subject'], $message, sprintf("%s\\r\
", $configuration['email.from']))){
    echo '<h1>Thankyou.</h1>';
    exit;
  }
 
}
?>
<h1>
 Sorry, an error occurred.
</h1>

Hi Ant -

At the mo i get this error message:
“Parse error: syntax error, unexpected T_IF in E:\domains\p\pauserefreshment.co.uk\user\htdocs\brochure.php on line 24”

I’ve corrected the php script to:

<?php
$configuration = array( 
'email.to'      => 'hello@pause.co.uk', 
'email.from'    => 'hello@pause.co.uk', 
'email.subject' => 'A website enquiry!'
);

if('POST' === $_SERVER['REQUEST_METHOD']){ 

$message = sprintf(   
"   This is a test message:-     
Name:   %s %s     
Email:  %s   

Thanks.   
",   
$_POST['name'],   
$_POST['secondname'],   
$_POST['email']
);  

ini_set('sendmail_from', $configuration['email.from'])

if(mail($configuration['email.to'], $configuration['email.subject'], $message, sprintf("%s\\r\
", $configuration['email.from']))){   echo '<h1>Thankyou.</h1>';   exit;
}
 
}
?>
<h1>Sorry, an error occured.</h1>

I also called my hosters and they cant help :frowning: Its hard to know for me to know where the problem is comming from. There are forms that allready work on the site so the original coders knew something I cant get my head around.

Well I’m not giving up yet but this is testing me big time :mad:

Is this correct if i want it to return info to pauseorders@googlemail.com?

<?php
$to = 'pauseorders@googlemail.com';
$subject = 'the subject';
$from = 'email@domain.com';
$message ='';