PHP form submission

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jan 16, 2013 11:50 pm

PHP form submission

Postby angienithya » Thu Jan 31, 2013 7:22 pm

Hi, I seem to run into a problem with this simple .php form submission code.
The message "Mail Sent" appears successfully - however I do not receive the contents of the form to the email that I had specified. Need help!!

Form Code (html)

<form method="post" action="test.php">
Subject<br><input type="text" name="subject" size="40">
Message<br><textarea name="message" rows="5" cols="40">
<button type="submit">Send</button>

PHP Code (.php)


$strTo = "";
$strSubj = $_POST["subject"];
$strMsg = $_POST["message"];

ini_set('SMTP', '');
ini_set("smtp_port", 25);


echo "Mail Sent.";


New php-forum User
New php-forum User
Posts: 13
Joined: Thu Sep 27, 2012 10:55 am

Re: PHP form submission

Postby rwhite35 » Fri Feb 01, 2013 5:01 am


You need to close your textarea tag.

Code: Select all

<textarea name="message" rows="5" cols="40"></textarea>

Consider using an email framework, I prefer PEAR. Make sure PEAR::Mail is installed on your server first, however most PHP/apache distro's are installed with PEAR.


Here is how you implement PEAR::Mail

Code: Select all

//assign path(required) to sendmail in parameter array
//set additional options here, if needed
$params['sendmail_path'] = '/usr/sbin/sendmail';

//instantiate the Mail object
$mail_object =& Mail::factory('sendmail',$params);

//send the mail   
$success = $mail_object->send($address,$headers,$body); //set earlier in script
   if (PEAR::isError($mail_object)) {print($mail_object->getMessage());}
      if ($success==true){
          $mes="The email successfully sent";
         header("Location: message.php?mes=$mes");

Using a framework (like PEAR::Mail) will optimize your email making sure it is "well formed". That means less of your emails will get bounced or dropped due to mail filtering.

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 10 guests