简体   繁体   English

HTML电子邮件未使用php发送

[英]Html email not sending using php

I am trying to send email in html format using php file but each time i receive email with this html code instead of html format of text ... if i move header code above message its not sending email so i put it at bottom please help ... thank you 我正在尝试使用php文件以html格式发送电子邮件,但是每次我收到使用此html代码而不是html文本格式的电子邮件时...如果我将标头代码移到消息上方而不发送电子邮件,那么我将其放在底部请帮助... 谢谢

<?php

  $name = $_POST['name'];

  $to = $_POST['to'];

  $from = $_POST['from'];

  $subject = $_POST['subject'];

  $message = "

  <html>

  <head>

  <body>

   <h1>

   <center>Meeting invitation</center>

  </h1>

 </body>

 </head>

 </html>

   ";

 $headers .= "MIME-Version: 1.0\r\n";

 $headers .= "Content-type: text/html; charset=ISO-8859-1\r\n";

 $headers = "From:" . $from; 


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

 ?> 

You forget ".", for string 您忘了“。”,为字符串

 $headers = "From:" . $from; 

must be 一定是

 $headers .= "From:" . $from; 

请添加此

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

Try below code.. 尝试下面的代码。

<?php
$name = $_POST['name'];

  $to = $_POST['to'];

  $from = $_POST['from'];

  $subject = $_POST['subject'];

  $message = "

  <html>

  <head>

  <body>

   <h1>

   <center>Meeting invitation</center>

  </h1>

 </body>

 </head>

 </html>

";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <gaurav@example.com>' . "\r\n";


mail($to,$subject,$message,$headers);
?>

You could something along the lines of 您可以按照以下方式进行操作

<?php
$val=mail('your email address', $_POST['subject'], $_POST['message']);
?>
<p>Your email has been sent.</p>

With the html page containing 与包含的html页面

  <input type="text" id="inputEmail" placeholder="Email" name="subject">
<textarea id="textarea"  rows="10" name="message" placeholder="Entermsg:"></textarea>

Using the mail function in PHP is simple and straight forward 在PHP中使用mail功能既简单又直接

In your code you'll need to modify 在您的代码中,您需要进行修改

$headers .= "From:" . $from;

Here is working example of mail code in PHP: 是PHP中邮件代码的工作示例:

<?php 

if($_GET["submit"] = "Send" )
{
     $namezz = $_GET["name"];
     $emailzz = $_GET["email"];
     $cityzz = $_GET["city"];
     $phonenozz = $_GET["phoneno"];
     $subj = $_GET["subject"];
     $commentszz = $_GET["msg"];
}

ini_set("SMTP","www.cccccc.in");

// email address to whoon to send 
$email = "ccc@gmail.com"; 

// The subject 
if( $subj == "No-Subject")
{
    $subj =  "New Enquiry form form ". $namezz; 
    $subject = $subj;
}
else
{
    $subject = $subj;
}


// The message 
$msgg = "Name :".$namezz ."\n 
Email :".$emailzz ."\n 
City :".$cityzz ."\n
Phone Number :".$phonenozz ."\n
Subject:".$subj ."\n
Message :".$commentszz;

$headers = "from :".$emailzz;

mail($email, $subject, $msgg, $headers); 

echo 'thanks for sending email';


?> 

Hope this will help you. 希望这会帮助你。

You forgot to put a . 你忘了放一个. in this piece of code 在这段代码中

$headers = "From:" . $from;

So this is your final code 这是您的最终代码

$headers .= "From:" . $from;

Because the . 因为. is used to concatenate in PHP. 用于在PHP中连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM