2017-12-30 6 views
1

이 스크립트는 작동하지만 방문 할 때 빈 이메일을 보냅니다. 그렇다면 제출 된 진짜. 나는 그것이 보내는 첫 번째 빈 것을 없애고 싶다. 이것은 내가 여기에서 찾은 대부분 편집 된 코드와 내가 필요로 함께 일할 다른 장소입니다.PHP PEAR Mail이 2 개의 이메일을 전송합니다

<?php 
ini_set("include_path", '/home/user/php:' . ini_get("include_path")); 
require_once "Mail.php"; 

$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$email = $_POST['email']; 
$address = $_POST['address']; 
$phone = $_POST['phone']; 
$contact = $_POST['contact']; 
$comments = $_POST['comments']; 
$from = "Info <[email protected]>"; 
$to = "Info <[email protected]>"; 
$subject = "Customer Contact Form"; 
$body = "If this works it will be edited a bit \n" . "First Name: " . $first_name . "\n" . "Last Name: " . $last_name . "\n" . "Email: " . $email . "\n" . "Address: " . $address . "\n" . "Phone: " . $phone . "\n" . "Please contact me by: " . $contact . "\n" . "Other Comments: " . $comments; 

$host = "mail.domain.net"; 
$username = "[email protected]"; 
$password = "emailpassword"; 

$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
     '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>"); 
//} 
?> 

<!DOCTYPE html> 
<head> 
<title>Form submission</title> 
</head> 
<body> 

<form action="" method="post"> 
First Name: <input type="text" name="first_name"><br> 
Last Name: <input type="text" name="last_name"><br> 
Email: <input type="text" name="email"><br> 
Address: <input type="text" name="address"><br> 
Phone: <input type="text" name="phone"><br> 
Perferred Form of Contact: <input type="text" name="contact"><br> 
Message:<br><textarea rows="5" name="comments" cols="30"></textarea><br> 
<input type="submit" name="submit" value="Submit"> 
</form> 

</body> 
</html> 

답변

1

양식 데이터를 확인하지 않으므로! 메일을 생성하고 보내는 코드 주위에 간단한 if(isset($_POST['first_name'])) 만 사용하면 양식을 보내면 이메일을 보내드립니다.

+0

감사합니다. 누군가 다른 사람이 알고 싶어하는 경우에, 그의 코드는 주석 처리 된 항목 바로 앞의 [그리고 다른] 헤더로 $ headers 앞에 간다. –

관련 문제