2013-08-26 5 views
-2

PHP를 처음 사용했습니다. 나는 간단한 연락 양식을 개발 중이다. 그 안에 내가 선택한 옵션을 기반으로 다른받는 사람에게 전자 메일을 보내고 싶습니다. 사용자가 경력 옵션을 선택하면 우편을 &으로 보내야합니다. 경력 우편 이외의 경우는 [email protected]으로 보내야합니다. 그러나 사용자가 다른 옵션을 선택하더라도 단 하나의 이메일로 이메일을받습니다. Pls 도움.선택한 옵션에 따라 다른 수신자에게 전자 메일을 보내는 PHP 양식

다음은

<?php 
$name = $_POST['name']; 
$company = $_POST['company']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$country = $_POST['country']; 
$interested = $_POST['interested']; 
$message = $_POST['message']; 
$formcontent="From: $name \n Company Name: $company \n Phone: $phone \n Country Name: $country \n Interested: $interested \n Message: $message"; 

function emailswitch($key) { 
    $to = array(
     'Career' => '[email protected]' 
    ); 
    $default = '[email protected]'; 
    return (!empty($to[$key]))?$to[$key]:$default; 
} 
$to = emailswitch($subject); 

$subject = "Enquiry from Website"; 
$mailheader = "From: $email \r\n"; 
mail($to, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "Thank You! <br /> We will get in touch with you as soon as possible."; 
?> 

HTML 내가 여기 함수에 대한 필요성이 표시되지 않는

<form name="frm" id="frm" method="POST" action="mail01.php"> 
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="contact-table"> 
    <tr> 
    <td class="contact-heading">Send a <span style="color:#171717;">Message</span></td> 
    <td>&nbsp;</td> 
    <td width="43%" rowspan="9" align="center" valign="top" style="padding-top:30px;"><img src="images/contact-us-new01.jpg" alt="Company Profile"></td> 
    </tr> 

    <tr> 
    <td width="43%" align="left" valign="middle"> 
    <div class="contact"><label>Name</label> 
    <input type="text" name="name" id="name" style="width:200px; float:right;" class="validate[required,custom[alphaspace]] for_obj" />&nbsp; </div> </td> 
    <td>&nbsp;</td> 
    </tr> 

    <tr> 
    <td width="43%" align="left" valign="middle"><div class="contact margin_1line"> 
     <label>Company Name</label> 
     <input type="text" name="company" id="company" style="width:200px; float:right;" /> 
     &nbsp; </div></td> 
    <td>&nbsp;</td> 
    </tr> 

    <tr> 
    <td align="left" valign="middle"> 
    <div class="contact margin_1line"><label>Email</label> 
    <input type="text" name="email" id="email" style="width:200px; float:right;" class="validate[required,custom[email]] for_obj" />&nbsp; </div> </td> 
    <td>&nbsp;</td> 
    </tr> 

    <tr> 
    <td align="left" valign="middle"><div class="contact margin_1line"> 
     <label>Phone</label> 
     <input type="text" name="phone" id="phone" style="width:200px; float:right;" /> 
     &nbsp; </div></td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td align="left" valign="middle"> 
    <div class="contact margin_1line"> 
     <label>Country Name</label> 
     <input type="text" name="country" id="country" style="width:200px; float:right;" class="validate[required,custom[alphaspace]] for_obj" /> 
     &nbsp; </div></td> 
    <td>&nbsp;</td> 
    </tr> 

    <tr> 
    <td align="left" valign="middle"><div class="contact margin_1line"> 
     <label>Interested</label> 
     <select type="text" name="interested" id="interested" style="width:210px; height:28px; border:#dddddd 1px solid; float:right;" class="validate[required,custom[alphaspace]] for_obj"> 
      <option value="Others">Others</option> 
      <option value="Product">Product</option> 
      <option value="Career">Career</option> 
      <option value="Information">Information</option> 
     </select> 
     &nbsp; </div></td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td> 
    <div class="contact margin_1line"><label for="message">Message</label> 
    <textarea name="message" id="message" class="validate[required] for_obj" rows="8" cols="10" style="width:200px; float:right;"></textarea>&nbsp; </div> </td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td align="left" valign="top" style="padding-left:142px; padding-top:20px;"> 
    <div class="contact"> 
    <label>&nbsp;</label> 
    <input type="submit" value="Send" class="butt custom_font" /> 
    <input type="reset" value="reset" class="butt custom_font" style=" float:right;" /> 
    </div></td> 
    <td>&nbsp;</td> 
    </tr> 
</table> 
</form> 
+0

그 다음 문제가 무엇인가요? –

+0

당신의 질문이 여기에 무엇인지 확실하지 않습니다, SureshK. 코드가 오작동하고 있습니까, 아니면 올바른 방향에 있는지 알고 싶습니까? – Dorvalla

+0

실제로 사용자가 다른 옵션을 선택하더라도 하나의 이메일 ID로만 메일을 받고 있습니다. – SureshK

답변

2

입니다 PHP 코드입니다. 그것은 불필요한 복잡성, IMO를 추가합니다. 난 문을 사용하여 선택한 양식 입력을 확인하고 이에 따라 $to 변수를 설정하면됩니다.

if($interested == 'Career') { 
    $to = '[email protected]'; 
} 
else { 
    $to = '[email protected]'; 
} 

$to 변수는 양식 옵션에 따라 설정됩니다 그것은 나중에 당신의 mail() 기능을 사용할 수 있습니다.

전체 코드 :이 도움이

<?php 

$name = $_POST['name']; 
$company = $_POST['company']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$country = $_POST['country']; 
$interested = $_POST['interested']; 
$message = $_POST['message']; 
$formcontent="From: $name \n Company Name: $company \nPhone: 
$phone \n Country Name: $country \nInterested: $interested \n Message: $message"; 

if($interested == 'Career') { //if career was selected 
    $to = '[email protected]'; 
} 
else { //other options 
    $to = '[email protected]'; 
} 

$subject = "Enquiry from Website"; 
$mailheader = "From: $email \r\n"; 
mail($to, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "Thank You! <br /> We will get in touch with you as soon as possible."; 

?> 

희망!

+0

지금은 감사합니다. – SureshK

+0

@SureshK : 환영합니다 :) –

+0

@Amal Murali 안녕하세요, 두 개 이상의 이메일에 예제를 수정 하시겠습니까? 감사. – Labanino

관련 문제