PHP and HTML feedback form

独自空忆成欢 提交于 2020-01-02 00:38:13

问题


I am trying to make a html and php feedback form and I am receiving an email that looks like this:

New contact form submission 
From:,, 
Email:,@email, 
,,

My html is:

<form method="POST" action="contactform.php">
    Name:<br/>
        <input type="text" name="name" />
        <br/><br/>
    EMail:<br/>
        <input type="text" name="email" />
        <br/><br/>
    Message: <br/>
        <textarea name"message" rows="10" cols="50" />
        </textarea><br/>
    <input type="submit" value="submit" />
</form>

My php is:

<?php
//converting veriables
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$recipient = 'nicholasparry@me.com'; 
$subject="Contact Form"; 
//creating message
$content = "New contact form submission \n From:,$name, \n Email:,@email, \n ,$message,"; 
//sending message
mail($recipient, $message, $content);
?>

Can anyone help me with what is wrong?


回答1:


It's:

$content = "New contact form submission \n From: ".$name.",\n Email: ".$email.", \n Message: ".$message;

and

<textarea name="message" rows="10" cols="50"></textarea>



回答2:


Start using Swiftmailer or PhpMailer, your life will be easier...

Swiftmailer example:

require_once 'lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
    ->setFrom(array('john@doe.com' => 'John Doe'))
    ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
    ->setBody('Here is the message itself');
$mailer->send($message);

PhpMailer example :

$mail             = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->AddAddress("whoto@otherdomain.com", "John Doe");
$mail->Subject    = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

I prefer Swiftmailer, but you select you best choice ;-)




回答3:


Wrap the variable names in curly braces. E.g. "From:,{$name},"



来源:https://stackoverflow.com/questions/12508333/php-and-html-feedback-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!