PHP form - blank emails

Hello! I’ve been trying to get a submission form working where i can grab customers information and process it. I’d ideally like it in the following format

Youtube name: namehere
firstname: namehere
lastname: name here
email: emailhere

etc

At the moment i am getting a blank email with nothing in the email itself. The header works fine and it grabs the email and puts it in the “from:” I’m a noob to HTML and PHP and had someone do this but they are unavailable for quite a while so i need to get this fixed as soon as i can. The PHP contact form came with a theme that i purchased and it works fine in the HTML contact form that it was supplied with but i needed it changed to fit my requirements. Any help is appreciated, thanks in advance!

My HTML code.

					<form id="" action="application/application.php" method="post" class="validateform" name="send-contact">
					
					 <div id="sendmessage">
							Your message has been sent. Thank you!
						</div>
						
						<input type="hidden" name="subject" value="Partnership  Applications" />

                                                 Youtube Channel Name <br>
						 <input type="text" name="ytname" placeholder="* Enter Your YouTube Name" data-rule="maxlen:4" data-msg="Please enter at least 4 chars"  />
						 <div class="validation"></div>

						 First Name <br>
						 <input type="text" name="firstname" placeholder="* Enter Your First Name" data-msg="Please enter at least 4 chars" />
						 <div class="validation"></div>
						
					          Last Name <br>
						 <input type="text" name="lastname" placeholder="* Enter Your Last Name" data-msg="Please enter at least 4 chars" />
						 <div class="validation"></div>
						
						 Your Paypal Email Address <br>
						 <input type="text" name="ppemail" placeholder="* Enter Your Paypal Email" data-msg="Please enter a valid email" />
						 <div class="validation"></div>
						
						 Your YouTube Email Address <br>
						 <input type="text" name="email" placeholder="* Enter Your YouTube Email" data-msg="Please enter a valid email" />
						 <div class="validation"></div>	

						 Skype <br>
						 <input type="text" name="skype" placeholder="* Enter Your Skype Name" data-msg="Please enter at least 4 chars"  />
						 <div class="validation"></div>										
						
						 <!--<button class="btn btn-theme margintop10 pull-left" type="submit" name="submit" value="Send">Submit message</button>-->
						   <span class="pull-right margintop20">* Please fill all required form field, thanks!</span>
						   <BR>
						   <BR>
						   <b>FORM IN MAINTENANCE!PLEASE SEND ALL<br> INFORMATION ABOVE DIRECTLY TO<br> <a href="mailto:Support@xvinitynetwork.com">Support@XvinityNetwork.com</a></b>
					

						   </form>

and this is my PHP

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{

$ytname = stripslashes($_POST['ytname']);
$firstname = stripslashes($_POST['firstname']);
$lastname = stripslashes($_POST['lastname']);
$ppemail = trim($_POST['ppemail']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$skype = stripslashes($_POST['skype']);


$error = '';



if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $email, $ytname,
     "From: ".$name." <".$email.">\\r\
"
    ."Reply-To: ".$email."\\r\
"
    ."X-Mailer: PHP/" . phpversion());


if($mail)
{
echo 'OK';
}

}


}
?>

My config.php includes the following;

<?php
// To
define("WEBMASTER_EMAIL", 'Support@XvinityNetwork.com');
?>

Thanks again

Hi MrPie, welcome to the forums. :slight_smile:

The main issue here is that the $mail = part doesn’t sent any of the data you have collected to the destination email. It should look something like this:

$mail = mail(WEBMASTER_EMAIL, $subject, $body, $header);

Then, above that line, paste this:


$body = "Name: $firstname $lastname\\r\
"  .
        "PayPal Email: $ppemail\\r\
"  .
        "Skype Name: $skype\\r\
"  .
        "Client Email: $email\\r\
";

$subject = "Your Chosen Email Subject";

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" .
    "Reply-To: ".$email . "\\r\
" .
    "X-Mailer: PHP/" . phpversion()); 

Because you don’t actually ask the user to type a subject, delete this line:


$subject = stripslashes($_POST['subject']); 

and add in a subject of your choice in this line I gave you above:

$subject = "[COLOR="#FF0000"][I]Your Chosen Email Subject[/I][/COLOR]";

I’m not an expert at this stuff, but see if those changes help at all. :slight_smile:

Hey Ralph, thanks for the speedy reply and thanks for helping :slight_smile: I’m a complete novice at this and i’m more of an art person rather than someone who codes lol

Apologies if i’ve got this wrong. When you say one line up i thought you meant literally so i dont know what i did and didn’t have to delete :lol:

I have made the changes you’ve suggested but i’m now not receiving any email at all, not sure what could be the problem.

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{

$body = "Name: $firstname $lastname\\r\
"  .
		"Youtube Name: $ytname/r\
" .
        "PayPal Email: $ppemail\\r\
"  .
        "Skype Name: $skype\\r\
"  .
        "Client Email: $email\\r\
";

$subject = "Partnership Applications";

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" .
    "Reply-To: ".$email . "\\r\
" .
    "X-Mailer: PHP/" . phpversion());


$error = '';



if(!$error)
{

	
$mail = mail(WEBMASTER_EMAIL, $subject, $body, $header);
     "From: ".$name." <".$email.">\\r\
"
    ."Reply-To: ".$email."\\r\
"
    ."X-Mailer: PHP/" . phpversion());


if($mail)
{
echo 'OK';
}

}


}
?>

I notice one back slash has become a forward slash here:

"Youtube Name: $ytname[COLOR="#FF0000"]/[/COLOR]r\
" .

Make sure to fix that. But I was pretty specific about what to do. I didn’t say anything about removing all this stuff:

$ytname = stripslashes($_POST['ytname']); 
$firstname = stripslashes($_POST['firstname']); 
$lastname = stripslashes($_POST['lastname']); 
$ppemail = trim($_POST['ppemail']); 
$email = trim($_POST['email']); 
$subject = stripslashes($_POST['subject']); 
$skype = stripslashes($_POST['skype']); 

So, in an attempt to be clearer:

Replace this code:

$mail = mail(WEBMASTER_EMAIL, $email, $ytname, 
     "From: ".$name." <".$email.">\\r\
" 
    ."Reply-To: ".$email."\\r\
" 
    ."X-Mailer: PHP/" . phpversion()); 

with this code:

$mail = mail(WEBMASTER_EMAIL, $subject, $body, $header);

Then, above that line, paste this:


$body = "Name: $firstname $lastname\\r\
"  .
        "PayPal Email: $ppemail\\r\
"  .
        "Skype Name: $skype\\r\
"  .
        "Client Email: $email\\r\
";

$subject = "Your Chosen Email Subject";

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" .
    "Reply-To: ".$email . "\\r\
" .
    "X-Mailer: PHP/" . phpversion()); 

Because you don’t actually ask the user to type a subject, delete this line:


$subject = stripslashes($_POST['subject']); 

from here:

$ytname = stripslashes($_POST['ytname']); 
$firstname = stripslashes($_POST['firstname']); 
$lastname = stripslashes($_POST['lastname']); 
$ppemail = trim($_POST['ppemail']); 
$email = trim($_POST['email']); 
[COLOR="#FF0000"]$subject = stripslashes($_POST['subject']); [/COLOR]  // delete this line, but not the others!!!!!!!!!!!!!!!!
$skype = stripslashes($_POST['skype']); 

Thanks again Ralph, i’ve made the changes you’ve mentioned but i am still not able to recieve any emails when the form is filled in :frowning:

Here’s the PHP as it stands right now

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{

$ytname = stripslashes($_POST['ytname']);
$firstname = stripslashes($_POST['firstname']);
$lastname = stripslashes($_POST['lastname']);
$ppemail = trim($_POST['ppemail']);
$email = trim($_POST['email']);
$skype = stripslashes($_POST['skype']);


$error = '';



if(!$error)
{
$body = "Name: $firstname $lastname\\r\
"  .
        "Youtube Name: $ytname\\r\
" .
        "PayPal Email: $ppemail\\r\
"  .
        "Skype Name: $skype\\r\
"  .
        "Client Email: $email\\r\
";

$subject = "Partnership Applications";

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" .
    "Reply-To: ".$email . "\\r\
" .
    "X-Mailer: PHP/" . phpversion());
	
$mail = mail(WEBMASTER_EMAIL, $subject, $body, $header);


if($mail)
{
echo 'OK';
}

}


}
?>

What happens if you change this:

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" . 
    "Reply-To: ".$email . "\\r\
" . 
    "X-Mailer: PHP/" . phpversion());

to this?

$header =  "From: " . $firstname $lastname . " <" .$email. ">\\r\
" . 
    "Reply-To: ".$email;

Are you getting any error messages?

I’m not sure how to check for errors, completely new to this.:blush: I can say that after that change the emails are getting sent however there is no subject and the contents of the email itself is blank.

Any help is still appreciated! I’m very confused as to why i am not receiving the $body to the email. I’ve fixed the “no subject” problem by adding the following code into the HTML but i still have no luck with the $body. I’d assume that the least it would do is send the fields with empty info but nada. I’ve also done some research which suggests that the $mail only works on Linux? so i double checked on Godaddy and we are on a Linux server, don’t know if that helps or not!

<input type="hidden" name="subject" value="Partnership  Application" />

Sorry for the delay. I’m not a PHP guy, though I can do simple forms like this; but there are many ways to do them, and I don’t think it’s worth continuing with the code you have, as it’s not great anyway. When I get time, if you like, I’ll have a go at doing it a different way that I know will work, and which will include security features, too. But I have to give priority to paid work, so it might take a while.

Appreciate the help ralph! It’s understandable. At the moment i just have a notice on the website to direct the information to my email. It would be great if i could get something working and it would mean a lot.

If it helps. This is the other form that came with the theme and it works perfectly for sending simple messages to me and such

<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);


$error = '';



if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
     "From: ".$name." <".$email.">\\r\
"
    ."Reply-To: ".$email."\\r\
"
    ."X-Mailer: PHP/" . phpversion());


if($mail)
{
echo 'OK';
}

}


}
?>

Thanks again Ralph. I’ll keep scouring the internet for any solutions in the meantime. :slight_smile:

Oh, your last post gives me a clue as to the problem, actually. Try this:



<?php 
/* 
Credits: Bit Repository 
URL: http://www.bitrepository.com/ 
*/ 

include 'config.php'; 

error_reporting (E_ALL ^ E_NOTICE); 

$post = (!empty($_POST)) ? true : false; 

if($post) 
{ 

$ytname = stripslashes($_POST['ytname']); 
$firstname = stripslashes($_POST['firstname']); 
$lastname = stripslashes($_POST['lastname']); 
$ppemail = trim($_POST['ppemail']); 
$email = trim($_POST['email']); 
$skype = stripslashes($_POST['skype']);  


$error = ''; 

$body = "Name: $firstname $lastname\\r\
"  . 
        "Youtube Name: $ytname\\r\
" . 
        "PayPal Email: $ppemail\\r\
"  . 
        "Skype Name: $skype\\r\
"  . 
        "Client Email: $email\\r\
"; 
  
$subject = "Partnership Applications"; 

if(!$error) 
{ 
$mail = mail(WEBMASTER_EMAIL, $subject, $body, 
     "From: ".$firstname $lastname ." <".$email.">\\r\
" 
    ."Reply-To: ".$email."\\r\
" 
    ."X-Mailer: PHP/" . phpversion()); 

if($mail) 
{ 
echo 'OK'; 
} 

} 


} 
?>


Hmm still nothing. I get no subject with just the php form. But having the following in the HTML solves this problem;

<input type="hidden" name="subject" value="Partnership  Application" />

As for the code. Still nothing. I’m starting to wonder if this is a problem on GoDaddys email service or something… :frowning:

Hmmph just dug this up. Hopefully it helps

You are able to use custom scripts for sending emails, and you will want to ensure that you are using relay-hosting.secureserver.net as the SMTP server. This relay server does not require authentication.

If you use the mail() fuction, it will not need to be specified.

and this is interesting

Thanks for the follow up with your experience. It is recommended that the ‘From’ address you are using in your script be an address using your hosted domain.

Just an FYI. The email i use (Support@XvinityNetwork.com) is from GoDaddy