English 中文(简体)
PHP Contact form editing
原标题:

Im not a pro at PHP, just starting actually and was wondering if you could help me.

Im trying to get this contact form to email me stating the Persons Name and the message like this.

Name: Fred Blogs Message: Message, Message.

But when I try all I get is the message, I cant seem to insert the name variable anywhere.

This is the code

<?php 
$name = $_REQUEST[ name ] ;
$email = $_REQUEST[ email ] ;
$message = $_REQUEST[ message ] ;
$subject = $_REQUEST[ subject ] ;

mail( "keiron.lowe@example.com", "Name: $name", "$subject", $message, "From: $email" );
header( "Location:contact.php" );
?>
最佳回答

You are passing too many parameters to the mail() function. Try something like this:

<?php 
ob_start();
$name = $_POST[ name ] ;
$email = filter_input(INPUT_POST,  email , FILTER_SANITIZE_EMAIL);
$message = $_POST[ message ] ;
$subject = strtr($_POST[ subject ],array( :  =>    , "
" =>    , "
" =>    ));

$message = "Name: {$name}
message: {$message}";
mail("redacted@example.com", $subject, $message, "From: {$email}");
header("Location: contact.php", true, 302);
ob_end_clean();
die;
?>
问题回答

You ve got the arguments mixed up a little:

mail( "keiron.lowe@gmail.com", $subject, "Name: $name
Message: $message", "From: $email" );

Additionally you shouldn t do "From: $email" without validating the email address - this will leave your script open to sending out spam.

Take a look at the manual for mail():

mail("keiron.lowe@gmail.com", "Name: $name", $message, "From: $email");

But anyways, I strongly suggest you don t rely on PHP s mail()-function as its return value does not indicate if a mail really has been sent. Use phpmailer for mailing instead.

Best wishes,
Fabian





相关问题
Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn t seem to work. while(...) { $msg .= "<...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

How to track an email in Java?

How I can track an email? I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

Web Link in a mail is not rendering as link in yahoo

string from = "abc@gmail.com"; string to = "xyz@gmail.com,xyz@yahoo.co.in"; string password="abcxyz"; MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

How to create an email mailing list

Im creating a coming soon page for a website im developing, and im adding an option for the user to enter their email address so we can email them when the site is up. How do I do this?

CCNet email does not include MSBuild results

We re using CCNet 1.4.4.83 but when an MSBuild task fails, we don t get the MSBuild results (i.e. missing file or whatever reason the compile failed) in the email notification. I do see the build ...

热门标签