Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP form submission

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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>
</form>

PHP Code (.php)

<?php

$strTo = "admin@aadithyatravel.com.my";
$strSubj = $_POST["subject"];
$strMsg = $_POST["message"];

ini_set('SMTP', 'mail1.netmyne.com');
ini_set("smtp_port", 25);

mail($strTo,$strSubj,$strMsg);

echo "Mail Sent.";

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

Re: PHP form submission

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

Hi,

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.

reference: http://pear.php.net/package/Mail/redirected

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.
rwhite35
New php-forum User
New php-forum User
 
Posts: 13
Joined: Thu Sep 27, 2012 10:55 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron