trim function issues


Posted on 16th Feb 2014 07:03 pm by admin

Hi guys, total noob here...

So I've been tinkering around with a html and am using php to email the subitted data to me. It's all working fine, except now I've changed the rules of the form a little and I can't seem to make it do a very simple task of converting field data to a string so that I can have it in the body of the email.

Did you know?Explore Trending and Topic pages for more stories like this.
Here's the code:

<?php

//If the form is submitted
if(isset($_POST['submit'])) {

//Check to make sure that the name field is not empty
if(trim($_POST['name']) == '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}

//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}

//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'mickyginger@googlemail.com'; //Put your own email address here
$subject = 'Interest from the website';
$body = $name . $email;
$headers = 'From:' .$name. '<'.$email.'>' . "rn" . 'Reply-To: ' . $email;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>

Which works fine and dandy, only there are other fields like 'date' and 'venue' which I want to add to the body of the email regardless of whether they have been left blank or not.

Basically I want it to do something like this:

If the form is submitted

if name is not empty
$name = trim($_POST['name']);

if email is not empty
$email = trim($_POST['name']);

if number is empty OR if not
$number = trim($_POST['number']);

if date is empty OR if not
$date = trim($_POST['date']);

if there is no error
$body = $name . $email . $number . $date

seems like it should be really simple but I've tried everything I can think of with no joy...
No comments posted yet

Your Answer:

Login to answer
173 Like 28 Dislike
Previous forums Next forums
Other forums

email CODING Problem
Email coding problem.

I need to send a section of the info to $tf and the same as a Cc to $em

Save username into DB
OkaY so I got my blog to actually save the posts and whatever, all I need now is for it to keep the

Hyperlink in PHP to MySQL record
Hello,

I am having trouble as i am new to php. I have connected to the database and I have di

update 2 columns by doing inner 2-column query
Hi,
is something like this possible?

update contract_all set col1,col2 =
(

phpMailer will not connect using SMTP
I am trying to use phpMailer with smtp:

Code: [Select]$mailer = new PHPMailer();
$mailer-&

quick question about System Change Number(SCN) in FlashBack Query topic
i know tht we can get the SCN of the database using flashback concept as follows

SQL>

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

To change the name of label on SAP screen XK02.
Hi All,

Can one suggest me how to change the label of an input field of a sap standard s

PHP and XML image gallery variable issue
I'm trying to display the large image on the same page as the thumbnails, to do that I'm passing a v

SAP Business Suite
Hi all:

Within the SAP Business Suite solution I would like to ask you the main differenc

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash