PHP Error Message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok, im gonna create a new php file with the advise you have just given and i will get back to you!

thank you for the help so far.. im sure ill come back for more!!
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

hey again.. just wonded how the data in the form could be sent to me, is there some kind of script that needs to be written?

i dont want it to be stored anywhere, just sent directly to an email address..

any help will be greatly appreciated
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Easy.

Use a mailing script.

This is THE best - viewtopic.php?t=48055
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

cheers ill take a look!
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

thats a very long script!!

where does it go?

i was thinking of using this one, what do you think?
if not, would you recommend one please?

Basic sendmail mailing

Code: Select all

<?php

require('../../Swift.php');
require('../../Swift/Connection/Sendmail.php');

$mailer = new Swift(new Swift_Connection_Sendmail);

//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected())
{
        //Sends a simple email
        $mailer->send(
                '"Joe Bloggs" <joe@bloggs.com>',
                '"Your name" <you@yourdomain.com>',
                'Some Subject',
                "Hello Joe it's only me!"
        );
        //Closes cleanly... works without this but it's not as polite.
        $mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);

?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Yeah, use that one, why not
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

good, where does it go?

in my original form handle script? or some where else?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Call the script once your form has been submited

Pseudo code

Code: Select all

if(form_is_submitted)
{
   // get user data from form

   // format data ready for emailing

   // send email
}
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

right, and that goes in the same php file?

at the end i presume..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Could go int he same PHP file, or you could submit the form data to another php script. Your choice.
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok, i'll put it in the same file..

how do you set it up

Code: Select all

<?php

if(form_is_submitted)
{
   // get user data from form

   // format data ready for emailing

   // send email
}

?>
<?php

$mailer = new Swift(new Swift_Connection_Sendmail);

//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected())
{
        //Sends a simple email
        $mailer->send(
                '"Joe Bloggs" <joe@bloggs.com>',
                '"Joe Bloggs" <joe@bloggs.com>',
                'subject',
                "message"
        );
        //Closes cleanly... works without this but it's not as polite.
        $mailer->close();
}
else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);

?>
if this is wrong (and no doubt it is)

can you show me?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Come on dude, think about it.

Ill give you a start

Code: Select all

<!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">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>We Are Individuals - Application Form Handle</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php
// Form Checker 2.0

// First Name
if (strlen($first) > 0)
{
  $first = stripslashes($first);
}

// If no name was entered
else
{
  $first = NULL;
        echo 'You did not enter your <b>First Name</b>';
}

// Last Name
if (strlen($last) > 0)
{
  $last = stripslashes($last);
}

// If no name was entered
else
{
  $last = NULL;
        echo 'You did not enter your <b>Last Name</b>';
}

// Name
$first = '$first';
$last = '$last';
$name = $first . ' ' . $last;
{
  echo 'Your name is <b>$name</b>';
}

// Email
if ( !(strlen($email) > 0) )
{
  $email = NULL;
        echo 'You did not enter your <b>Email</b>';
}

// Gender
if (isset($gender))
{
  if ($gender == 'M')
        {
          $message = 'You chose <b>Male</b>';
        }
        elseif ($gender == 'F')
        {
          $message = 'You chose <b>Female</b>';
        }
}

// If no gender was entered
else
{
  $gender = NULL;
        echo 'You did not choose your <b>Gender</b>';
}

// Age
if (strlen($age) > 0)
{
  if ($age == '16')
        {
          $message = 'You chose <b>16</b>';
        }
        if ($age == '17')
        {
          $message = 'You chose <b>17</b>';
        }
        if ($age == '18')
        {
          $message = 'You chose <b>18</b>';
        }
        if ($age == '19')
        {
          $message = 'You chose <b>19</b>';
        }
        if ($age == '20')
        {
          $message = 'You chose <b>20</b>';
        }
}

// If no age was entered
else
{
  $age = NULL;
        echo 'You did not choose your <b>Age</b>';
}

// Instrument(s)
if (strlen($instruments) > 0)
{
  if ($instruments == 'Bass')
        {
          $message = 'You chose <b>Bass</b>';
        }
        if ($instruments == 'Drums')
        {
          $message = 'You chose <b>Drums</b>';
        }
        if ($instruments == 'Guitar')
        {
          $message = 'You chose <b>Guitar</b>';
        }
        if ($instruments == 'Keyboard')
        {
          $message = 'You chose <b>Keyboard</b>';
        }
        if ($instruments == 'Sing')
        {
          $message = 'You chose <b>Sing</b>';
        }
}

// If no instrument(s) entered
else
{
  $instruments = NULL;
        echo 'You did not choose a(n) <b>Instrument(s)</b>';
}

// Where they live
if (strlen($town) > 0)
{
  if ($town == 'braintree')
        {
          $message = 'You chose <b>Braintree</b>';
        }
        if ($town == 'chelmsford')
        {
          $message = 'You chose <b>Chelmsford</b>';
        }
        if ($town == 'dunmow')
        {
          $message = 'You chose <b>Dunmow</b>';
        }
}

// No town was entered
else
{
  echo 'You did not choose a <b>town</b>';
}

// Comments
if (strlen($comments) > 0)
{
  $comments = stripslashes($comments);
}

// If no comments were entered
else
{
  $comments = NULL;
        echo 'You did not enter any <b>Comments</b><br />';
        echo 'If you do not want to enter <b>Comments</b>, enter <i>none</i>';
}

// If everything was filled out correctly
if ($first && $last && $email && $gender && $age && $instruments && $town && $comments)
{
  echo "Thank you <b>$name</b>, I will reply to you at <i>$email</i>.";
  echo $message;
		

	/*
	// NOW LETS SEND THIS INFO VIA EMAIL
	*/

	require('../../Swift.php');
	require('../../Swift/Connection/Sendmail.php');
	 
	/*
	// CREATE AN EMAIL TO SEND
	*/
	$message = "blah blah blah"; // CHANGE THIS BIT
	
	$mailer = new Swift(new Swift_Connection_Sendmail);
	
	//If anything goes wrong you can see what happened in the logs
	if ($mailer->isConnected())
	{
			//Sends a simple email
			$mailer->send(
					'"Joe Bloggs" <joe@bloggs.com>', // change this
					'"Joe Bloggs" <joe@bloggs.com>', // change this
					'subject', // change this
					$message
			);
			//Closes cleanly... works without this but it's not as polite.
			$mailer->close();
	}
	else echo "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1); 

}
?>

</body>
</html>
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

im sorry, but as i said before, i dont know php, i am learning here! give me a break!!

thank you for your help though..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

herbie497 wrote:im sorry, but as i said before, i dont know php, i am learning here! give me a break!!

thank you for your help though..
Im just trying to be motivational. yYou'll get more satifaction if you figure it out yourself...and learn quicker Image
herbie497
Forum Newbie
Posts: 17
Joined: Tue Aug 01, 2006 4:36 am

Post by herbie497 »

ok well.. thanks..

just saw this..

Code: Select all

require('../../Swift.php');
require('../../Swift/Connection/Sendmail.php');
i dont understand..

and

Code: Select all

//Sends a simple email
   $mailer->send(
   '"Name" <email@email.com>',
   '"Name" <email@email.com>',
   'subject',
   $message
does this send an email to both the supplied addresses?
dont i need just one?
Post Reply