2016-08-24 32 views
0

我想这个代码的形式实际上是工作,并通过电子邮件发送给博客的管理员电子邮件。 我不知道,让它变成现实。如何在博客发送到管理员电子邮件中创建自定义表单?

<form id="partner" action="" method="post" name="contact-form" enctype="text/plain"> 
    <h3><span>Daftar Partner</span></h3> 
    <label>Name Fansub</label> 
    <input type="text" name="nama" placeholder="A3Substream" size="20" /> 
    <label>Website</label> 
    <input type="text" name="alamat" placeholder="http://www.a3substream.net" size="20" /> 
    <label>Link Banner</label> 
    <input type="text" name="mail" placeholder="imagelink" size="20" /> 
    <button id="ContactForm1_contact-form-submit" type="button">Kirim sekarang!</button> 
    <button type="reset" value="Batal">Batal</button> 
    <div style="max-width: 222px; text-align: center; width: 100%;"> 
     <div id="ContactForm1_contact-form-error-message"> 
     </div> 
     <div id="ContactForm1_contact-form-success-message"> 
     </div> 
    </div> 
</form> 
+0

可能重复[发送电子邮件与PHP从HTML表单提交相同的脚本](http://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on使用同一个脚本提交) – showdev

+0

也相关:[如何创建一个可以使用html发送电子邮件的电子邮件表单](http://stackoverflow.com/questions/8239782/how-to-create-an-电子邮件形式,可以发送电子邮件使用html) – showdev

+0

很多教程在那里,首先尝试它们,当你尝试一个,它不起作用,然后来,有人会帮助你从那里,之后你尝试了一些东西。 –

回答

0

这取决于您正在使用的服务器。有些人会接受下面提供的简单例子。添加PHP代码发送邮件

<?php 

if (isset($_POST['nama']) && ((isset($_POST['nama']) != ""))) { 
$nameofsender = $_POST['nama']; 
$to = '[email protected]'; 
$message = $_POST['mail']; 
$body ='<html> 
<body> 
<div class="content"> 
<p style="text-align:center;">'.$message.'<p><br /> 
</div> 
</body>'; 

$headers='MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: MY BLOG <[email protected]>' . "\r\n"; 
$subject = "$nameofsender - Message from blog"; 
//mail function 
$mail = mail($to, $subject, $body, $headers); 

if(!$mail) { 
    echo "Error sending email"; 
} 
else { 
    echo "Your email was sent successfully."; 
} 
} 
?> 

YOUR FORM...... 

有些服务器是严格更使基于Windows的服务器和发送邮件,如下面的代码

/*email starts*/  
require_once "http://www.yourblog.com/Mail.php"; 

$from = "Your blog <[email protected]>"; 
$email = '[email protected]'; 
$to = "<$email>"; 
$subject = "$nameofsender - Message from blog"; 
$message = $_POST['mail']; 
$body = $body ='<html> 
<body> 
<div class="content"> 
<p style="text-align:center;">'.$message.'<p><br /> 
</div> 
</body>'; 

$host = "mail.yourwebsite.com"; 
$username = "[email protected]"; 
$password = "passwordtousernameabove"; 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 
$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 


$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'port' => 25, 
    'auth' => true, 

    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
    echo("<p>Message successfully sent!</p>"); 
} 
YOUR FORM.... 

为了更好地理解谷歌的教程之前,可能需要更多的细节这个话题,因为它是一个镜头,但广泛的有趣的话题。问候

+0

对不起,我不包括我的博客信息,但我使用博客,你知道博客不支持PHP,所以如果你乐意给我另一种方式,如JavaScript或其他支持博主。 –

+0

它必须支持php。保存您的文件扩展名为。 PHP。它不是关于博客。它关于服务器。但这是我能给出的最佳解决方案。 –

+0

所以我不能只是从博主使用ID或JavaScript添加功能,老实说使用PHP是非常复杂的,但真的很感谢你。如果您的文件保存为例如 –

相关问题