Jump to content

Recommended Posts

I'm using the mail() in my application form, but I can't seem to get the email to send what the user has entered in the form to me.

 

It's been confusing me for hours now!

 

<?php

if($_POST['submit'])
{

$username = $_POST['username'];
$email = $_POST['email'];
$age = $_POST['age'];
$location = $_POST['location'];
$duration = $_POST['duration'];
$griefed = $_POST['griefed'];
$access = $_POST['access'];
$builder = $_POST['builder'];
$fill = $_POST['fill'];

if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){

$to = "dtoyee@dawncraftmc.com";
$from = '$email';
$subject = "Creative World Application" ; 
$message = "Username: $username /n" .
			"Email: $email /n" .
			"Age: $age /n" . 
			"Location: $location /n" .
			"Duration on the server: $duration /n" .
			"Ever griefed: $griefed /n" . 
			"Access to the new world: $access /n" . 
			"Are you a good builder: $builder /n" . 
			"Anything else that we should know: $fill /n" .

mail($to, $from, $subject, $message);

echo "Application was sent!";
}
	else
		{
			echo "All fields are required!";
		}
}

?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form method="POST">
<center>
In-Game Name: <input type="text" name="username"/><p>
    Email: <input type="text" name="email" /><p>
    Age: <input type="text" name="age" /><p>
    Location: <input type="text" name="location" /><p>
    How long have you beed on Dawncraft: <input type="text" name="duration" /><p>
    Have you ever griefed: <input type="text" name="griefed" /><p>
    Why do you want access to the creative world: <input type="text" name="access" /><p>
    Do you consider yourself to be a good builder: <input type="text" name="builder" /><p>
    Anything else that we should know: <textarea name="fill"></textarea><p>
    <input type="submit" name="submit" value="Submit" />
    
</center>
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/257197-how-do-i/
Share on other sites

On this line: $from = '$email';, you assign the string literal '$email' to the $from variable. You don't need quotes at all to assign the value of a variable to another variable.

 

The arguments in the mail function aren't right. From: is a header, not an argument by itself.

Link to comment
https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318399
Share on other sites

On this line: $from = '$email';, you assign the string literal '$email' to the $from variable. You don't need quotes at all to assign the value of a variable to another variable.

 

The arguments in the mail function aren't right. From: is a header, not an argument by itself.

 

Hmm, what will I need to do to the mail function? I thought the mail function was correct, but i'm new at php.

 

Do I have this correct, the email sends but the variables inside the of $message do not appear?

 

That is correct. It actually shows the $subject in the message area.

 

 

Also, I like how fast replies are on this forum!

Link to comment
https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318415
Share on other sites

Can't believe that script doesn't have a parse error:

<?php //syntax highlighting.

if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){

$to = "dtoyee@dawncraftmc.com";
$from = '$email';
$subject = "Creative World Application" ; 
$message = "Username: $username /n" .
			"Email: $email /n" .
			"Age: $age /n" . 
			"Location: $location /n" .
			"Duration on the server: $duration /n" .
			"Ever griefed: $griefed /n" . 
			"Access to the new world: $access /n" . 
			"Are you a good builder: $builder /n" . 
			"Anything else that we should know: $fill /n" .  //<- You need to remove the . (period) and place a ; (semicolon).

mail($to, $from, $subject, $message);

Link to comment
https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318427
Share on other sites

Can't believe that script doesn't have a parse error:

<?php //syntax highlighting.

if($username && $email && $age && $location && $duration && $griefed && $access && $builder && $fill){

$to = "dtoyee@dawncraftmc.com";
$from = '$email';
$subject = "Creative World Application" ; 
$message = "Username: $username /n" .
			"Email: $email /n" .
			"Age: $age /n" . 
			"Location: $location /n" .
			"Duration on the server: $duration /n" .
			"Ever griefed: $griefed /n" . 
			"Access to the new world: $access /n" . 
			"Are you a good builder: $builder /n" . 
			"Anything else that we should know: $fill /n" .  //<- You need to remove the . (period) and place a ; (semicolon).

mail($to, $from, $subject, $message);

 

It did have a semicolon before I posted the thread. I was testing to try and get them to include each other, but I guess it didn't work, but i'll be changing them back to a semicolon soon!

Link to comment
https://forums.phpfreaks.com/topic/257197-how-do-i/#findComment-1318429
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.