/    Sign up×
Community /Pin to ProfileBookmark

I’m trying to get my form submission to submit, but when I do, I get an error from my server side: Could not send mail! Please check your PHP mail configuration.

The error lies in this area, but I’m not entirely sure how to go about fixing it.

[code=php]$email_content = “Name: $user_Namen”;
$email_content .= “Email: $user_Emailnn”;
$email_content .= “Project Budget:n$user_Projectn”;
$email_content .= “Project ETA:n$$user_ProjectETAn”;
$email_content .= “Project Details:n$$messagen”;[/code]

full code:

[code=php]<?php
if($_POST)
{
$to_Email = “”; //Replace with recipient email address
$subject = ‘Project Submissions’; //Subject line for emails

//check if its an ajax request, exit if not
if(!isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) AND strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) != ‘xmlhttprequest’) {

//exit script outputting json data
$output = json_encode(
array(
‘type’=>’error’,
‘text’ => ‘Request must come from Ajax’
));

die($output);
}

//check $_POST vars are set, exit if any missing
if(!isset($_POST[“userName”]) || !isset($_POST[“userEmail”]) || !isset($_POST[“userProject”]) || !isset($_POST[“userProjectETA”]) || !isset($_POST[“userMessage”]))
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Some fields may have been left blank, please go back and correct them!’));
die($output);
}

//Sanitize input data using PHP filter_var().
$user_Name = filter_var($_POST[“userName”], FILTER_SANITIZE_STRING);
$user_Email = filter_var($_POST[“userEmail”], FILTER_SANITIZE_EMAIL);
$user_Project = filter_var($_POST[“userProject”], FILTER_SANITIZE_NUMBER_INT);
$user_ProjectETA = filter_var($_POST[“userProjectETA”], FILTER_SANITIZE_NUMBER_INT);
$user_Message = filter_var($_POST[“userMessage”], FILTER_SANITIZE_STRING);

//additional php validation
if(strlen($user_Name)<2) // If length is less than 4 it will throw an HTTP error.
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Your name is too short, please add more characters!’));
die($output);
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Please enter a valid email address!’));
die($output);
}

if(strlen($user_Project)<2) //check emtpy message
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘The project budget msut contain numbers only!’));
die($output);
}
if(strlen($user_ProjectETA)<5) //check emtpy message
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Please format the project ETA like 01/01/2000!’));
die($output);
}
if(strlen($user_Message)<15) //check emtpy message
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Your message is too short, please add more characters to the message!’));
die($output);
}

//proceed with PHP email.
$headers = ‘From: ‘.$user_Email.” . “rn” .
‘Reply-To: ‘.$user_Email.” . “rn” .
‘X-Mailer: PHP/’ . phpversion();

$email_content = “Name: $user_Namen”;
$email_content .= “Email: $user_Emailnn”;
$email_content .= “Project Budget:n$user_Projectn”;
$email_content .= “Project ETA:n$$user_ProjectETAn”;
$email_content .= “Project Details:n$$messagen”;

if(!$sentMail)
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Could not send mail! Please check your PHP mail configuration.’));
die($output);
}else{
$output = json_encode(array(‘type’=>’message’, ‘text’ => ‘Thanks <strong>’.$user_Name .'</strong> for your project submission! ‘));
die($output);
}
}
?>[/code]

I replaced it with this code:

[code=php] $sentMail = @mail($to_Email, $subject, $user_Message .’ -‘.$user_ProjectETA, $headers);[/code]

and it submitted successfully, however I’m trying to get all fields to send to an email.

I even tried

[code=php]$sentMail = @mail($to_Email, $subject, $user_Project, $user_ProjectETA, $user_Message .’ -‘.$user_Name $headers); [/code]

sadly it doesn’t work.

any ideas?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJul 17.2014 — What does this mean:

"and it submitted successfully, however I'm trying to get all fields to send to an email."

If your mail statement executed cleanly, what else do you want to do?

AND please stop using @ in front of your commands. If there is a problem you DON'T want to suppress the error!!! Ever!
Copy linkTweet thisAlerts:
@kristhecaptainauthorJul 17.2014 — What does this mean:

"and it submitted successfully, however I'm trying to get all fields to send to an email."

If your mail statement executed cleanly, what else do you want to do?

AND please stop using @ in front of your commands. If there is a problem you DON'T want to suppress the error!!! Ever![/QUOTE]


well i replace the above with this;

$sentMail = @mail($to_Email, $subject, $user_Message .' -'.$user_ProjectETA, $headers); [/QUOTE]

i try adding in like $user_Name etc and it won't submit.. it's like it only submit 2 of those "$user_" fields.
Copy linkTweet thisAlerts:
@ginerjmJul 18.2014 — 1 - Is php error checking turned on?

2 - WHY DO YOU SUPPRESS ERRORS WITH THE @ SIGN, but then try to capture a return value from the 'mail' call? Take off the @ and see what error message you get out of your statement.
Copy linkTweet thisAlerts:
@rootJul 18.2014 — Shouldn't this [code=php]if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')[/code]

be

[code=php]if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')[/code]
Copy linkTweet thisAlerts:
@ginerjmJul 22.2014 — Turn On PHP Error Checking.
×

Success!

Help @kristhecaptain spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...