2013-06-18 3 views
0

phpmailer를 사용하여 html 양식을 통해 보낸 전자 메일의 "to"주소를 설정하려고합니다. 최종 목표는 사용자가 자신의 필요에 따라 연락하는 사람을 선택할 수있게하는 드롭리스트를 활용하는 것입니다. 그러나 PHP에 대해 많이 알지 못해서 단계별로 진행 중이며 이미 붙어 있습니다.PHP 메일러의 "to"주소

구매 한 사이트와 함께 제공되는 예를 사용하고 있지만 입력란을 포함하도록 수정하려고합니다. 지금은 단순히 새로운 변수를 표시하려고 시도했지만 성공하지는 못했습니다.

<form name="contact" method="post" action="phpmailer.php" class="af-form" id="af-form"> 
<div class="af-outer af-required"> 
    <div class="af-inner"> 
     <label for="toemail" id="toemail_label">To Whom:</label> 
     <input type="text" name="toemail" id="toemail" size="30" value="" class="text-input span8"/> 
     <label class="error" for="toemail" id="toemail_error">To field is required.</label> 
    </div> 
</div> 
<div class="af-outer af-required"> 
    <div class="af-inner"> 
     <label for="name" id="name_label">Your Name:</label> 
     <input type="text" name="name" id="name" size="30" value="" class="text-input span8"/> 
     <label class="error" for="name" id="name_error">Name is required.</label> 
    </div> 
</div> 
<div class="af-outer af-required"> 
    <div class="af-inner"> 
     <label for="email" id="email_label">Your Email:</label> 
     <input type="text" name="email" id="email" size="30" value="" class="text-input span8"/> 
     <label class="error" for="email" id="email_error">Email is required.</label> 
    </div> 
</div> 
<div class="af-outer af-required"> 
    <div class="af-inner"> 
     <label for="input-message" id="message_label">Your Message:</label> 
     <textarea name="message" id="input-message" cols="30" class="text-input span8"></textarea> 
     <label class="error" for="input-message" id="message_error">Message is required.</label> 
    </div> 
</div> 
<div class="af-outer af-required"> 
    <div class="af-inner"> 
     <input type="submit" name="submit" class="form-button btn btn-large" id="submit_btn" value="Send Message!" /> 
    </div> 
</div> 

이름, 이메일, 메시지 필드를 잘 집어 내가받을 이메일에 채울 얻을이 바로 지금이 자리에있는 HTML 양식입니다. 그러나 "toemail"필드는 표시되지 않습니다. 다음은 phpmailer에 사용하고있는 process.php입니다. 그러나, 나는 "toemail"입력에 대해 '없음 주소 입력'내 다시 가을 오류 메시지,

<?php 
if ((isset($_POST['toemail'])) && (strlen(trim($_POST['toemail'])) > 0)) { 
    $toemail = stripslashes(strip_tags($_POST['toemail'])); 
} else {$toemail = 'No to address entered';} 
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) { 
    $name = stripslashes(strip_tags($_POST['name'])); 
} else {$name = 'No name entered';} 
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) { 
    $email = stripslashes(strip_tags($_POST['email'])); 
} else {$email = 'No email entered';} 
if ((isset($_POST['message'])) && (strlen(trim($_POST['message'])) > 0)) { 
    $message = stripslashes(strip_tags($_POST['message'])); 
} else {$message = 'No phone entered';} 
ob_start();d 
?> 
<html> 
<head> 
<style type="text/css"> 
</style> 
</head> 
<body> 
<table width="550" border="1" cellspacing="2" cellpadding="2"> 
    <tr bgcolor="#eeffee"> 
    <td>To Whom:</td> 
    <td><?=$toemail;?></td> 
    </tr> 
    <tr bgcolor="#eeffee"> 
    <td>Name</td> 
    <td><?=$name;?></td> 
    </tr> 
    <tr bgcolor="#eeeeff"> 
    <td>Email</td> 
    <td><?=$email;?></td> 
    </tr> 
    <tr bgcolor="#eeffee"> 
    <td>Message</td> 
    <td><?=$message;?></td> 
    </tr> 
</table> 
</body> 
</html> 
<? 
$body = ob_get_contents(); 

$to = 'personalemailtousefortesting.com'; 
$email = '[email protected]'; 
$fromaddress = "[email protected]"; 
$fromname = "Online Contact"; 

require("phpmailer.php"); 

$mail = new PHPMailer(); 

$mail->From  = "[email protected]"; 
$mail->FromName = "Contact Form"; 
$mail->AddAddress("[email protected]","Name 1"); // addresses here 

$mail->WordWrap = 50; 
$mail->IsHTML(true); 

$mail->Subject = "Contact form submitted"; 
$mail->Body  = $body; 
$mail->AltBody = "This is the text-only body"; 

if(!$mail->Send()) { 
    $recipient = '[email protected]'; 
    $subject = 'Contact form failed'; 
    $content = $body; 
    mail($recipient, $subject, $content, "From: [email protected]\r\nReply-To: $email\r\nX-Mailer: DT_formmail"); 
    exit; 
} 
?> 

내가 얻을 이메일

는 이름, 이메일을 채우고 메시지가 잘 필드.

이것은 1 번 발행입니다. 누구나 볼 필요가 있다면 phpmailer.php를 게시 할 것입니다. 변수를 먼저 정의해야할지 모르겠다.

작업을 마치면 사용자가 원하는대로 이메일을 보낼 수 있도록 드롭 다운 목록에서 작동하게해야합니다.

그런 다음 실제 송신 주소로 설정해야합니다. 송부 목적으로 실제 주소를 설정하는 방법을 모르겠습니다. 나는 ... 내가 뭔가 등에

$mail->AddAddress("[email protected]","Name 1"); // addresses here 

을 변경하는 것이

$mail->AddAddress($toemail,"Name 1"); // addresses here 

가정 것이다 ...하지만 가능성은 정확하지입니다 있습니다.

도움이된다면 도움이 될 것입니다.

내 phpmailer.php를 볼 필요가 있다면 게시 할 수도 있습니다.

다시 감사합니다, 당신이 찾을 수 없습니다 그냥 넣다

-Rocky 콜트 TumTum

+0

BUMP !! 아직도 이것에 대한 응답을 얻지 못했습니다. –

답변

0

, 이것은 PHP 매뉴얼 사이트에 게재 된 것입니다.

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

// message 
$message = ' 
<html> 
<head> 
    <title>Birthday Reminders for August</title> 
</head> 
<body> 
    <p>Here are the birthdays upcoming in August!</p> 
    <table> 
    <tr> 
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
    </tr> 
    <tr> 
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
    </tr> 
    <tr> 
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td> 
    </tr> 
    </table> 
</body> 
</html> 
'; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 
?> 
+0

답장을 보내 주셔서 감사합니다. 그러나 어떻게 저에게 도움이되는지 잘 모르겠습니다. –

+0

여러 수신자를 설정하고 있지만 "가변"수신자를 설정하려고합니다. 따라서 연락처 양식에서 "누구에게 :"사람이 선택되었는지에 따라 전자 메일의 전송 위치가 결정됩니다. 그게 더 의미가 있기를 바랍니다. 혼란을 드려 죄송합니다. –

+0

* BUMP * 나는 아직도 이것을 이해하지 못했고, 나는 내 손을 잡을 수있는 모든 것을 읽었으며 그것이 왜 효과가 없는지 알 수 없다. –

관련 문제