2014-04-05 3 views
0

기본 웹 사이트에 html 양식이 있습니다. 제출 된 버튼을 제출 한 후 양식에 입력 한 데이터를 제출하면 내 이메일로 전송되기를 원합니다. 단지 화면에 보낸 메시지를 표시합니다,하지만 난 이메일 계정을 확인할 때 나는 이메일을받지 못했다 "Sent.html"..양식 데이터를 이메일로 보내려고합니다.

HTML 양식 ....

<form name="contactform" method="POST" action="formphp.php"> 

<table width="450px"> 
<tr> 
    <td valign="top"> 
    <label for="name">Name *</label> 
</td> 
    <td valign="top"> 
    <input type="text" name="Name" maxlength="50" size="30"> 
</td> 
</tr> 
<tr> 

    <td valign="top""> 

    <label for="email">Email *</label> 
</td> 
    <td valign="top"> 
    <input type="text" name="Email" maxlength="50" size="30"> 
</td> 
</tr> 

<td valign="top"> 

    <label for="subject">Subject *</label> 
</td> 
    <td valign="top"> 
    <input type="text" name="Subject" maxlength="50" size="30"> 
</td> 
</tr> 

<tr> 
    <td valign="top"> 
    <label for="questions">Question/Feedback *</label> 
</td> 
    <td valign="top"> 
    <textarea name="Question" cols="40" rows="5"></textarea> 
</td> 
</tr> 

<tr> 
    <td colspan="2" style="text-align:center"> 
    <input type="submit" value="Submit"> 
</td> 
</tr> 
</table> 
</form> 

PHP 코드입니다. ..

<?php 
/* set email */ 
$myemail = "[email protected]"; 

/* declare id */ 
$Name = $_POST['Name']; 
$Email = $_POST['Email']; 
$subject = $_POST['Subject']; 
$Questions = $_POST['Questions']; 

/* set subject heading */ 
$subject = "Subject"; 

/* Message */ 
$message = "$Name + $Email + $Questions 

"; 

/* redirect this form after email sent */ 
header("location: sent.html"); 
?> 

답변

2

시도를 insted. PHP에서 메일을 보내려면이 구문을 사용합니다 : 귀하의 경우에는

mail($sendto, $subject, $msg) 

을, 당신은 당신이 당신의 $ 메시지를 설정 한 후 바로 코드를 넣어 것, 그리고 코드는 다음과 같습니다

mail($myemail, $subject, $message) 

PHP 메일에 대한 자세한 내용은 여기를 참조하십시오. http://php.net/manual/en/function.mail.php

0

https://github.com/PHPMailer/PHPMailer

$mail = new PHPMailer(true); 

$html = ' 
<!DOCTYPE html> 
<html> 
<head> 
    <title>Contact</title> 
</head> 
<body> 
    CONTENT HERE 
</body> 
</html> 
'; 

try { 
    $mail->AddAddress('[email protected]', 'Domain Name'); 
    $mail->SetFrom('[email protected]', 'Domain Name'); 
    $mail->Subject = 'Contact from domain.com'; 
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
    $mail->MsgHTML($html); 
    if(!$mail->send()) { 
     echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 
     exit; 
    }else{ 
     header("location: sent.html"); 
    } 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
} 
1

PHP 코드와 문제는 당신이 실제로 이메일을 보낸 적이 있다는 것입니다 : g 코드는 header("location: sent.html");의 PHPMailer 라이브러리를 사용하여

if(mail($Email,$subject,$message)) 
    header("location: sent.html"); 
else 
    die('Failed to send an email'); 
관련 문제