2013-10-30 40 views
1

PHP的新手在这里...PHPMailer如果其他人根据用户的下拉选择

试图把一个if/elseif语句放入我的php代码的表单电子邮件。

如果用户选择“桑迪”,那么电子邮件应该去桑迪的电子邮件地址。如果用户选择“史蒂夫”发送到史蒂夫的电子邮件地址,等等。这是我到目前为止的代码。任何意见表示赞赏。

<?php 

require_once('phpmailer/class.phpmailer.php'); 

$mail = new PHPMailer(); 

if(isset($_POST['template-contactform-submit']) AND $_POST['template-contactform-submit'] == 'submit') { 

if($_POST['template-contactform-name'] != '' AND $_POST['template-contactform-email'] != '' AND $_POST['template-contactform-subject'] != '' AND $_POST['template-contactform-message'] != '') { 

    $name = $_POST['template-contactform-name']; 

    $email = $_POST['template-contactform-email']; 

    $subject = $_POST['template-contactform-subject']; 

    $message = $_POST['template-contactform-message']; 

    $botcheck = $_POST['template-contactform-botcheck']; 

    if($_POST['template-contactform-employee'] = 'Sandy'): 

     { 

     $toemail = '[email protected]'; 

     $toname = 'Sandy'; 

     } 


    elseif($_POST['template-contactform-employee'] = 'Steve'): 

     { 

     $toemail = '[email protected]'; 

     $toname = 'Steve'; 

     } 

    elseif($_POST['template-contactform-employee'] = 'Nick'): 

     { 

     $toemail = '[email protected]'; 

     $toname = 'Nick'; 

     } 

    else: { 

     $toemail = "[email protected]"; 

     $toname = "Support"; 

     } 

    endif; 

    $body = "$message"; 

    if($botcheck == '') { 

     $mail->SetFrom($email , $name); 

     $mail->AddReplyTo($email , $name); 

     $mail->AddAddress($toemail , $toname); 

     $mail->Subject = $subject; 

     $mail->MsgHTML($body); 

     $sendEmail = $mail->Send(); 

     if($sendEmail == true): 

      echo '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button>We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.</div>'; 

     else: 

      echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '</div>'; 

     endif; 

    } else { 

     echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>Bot <strong>Detected</strong>.! Clean yourself Botster.!</div>'; 

    } 

} else { 

    echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>Please <strong>Fill up</strong> all the Fields and Try Again.</div>'; 

} 

} else { 

echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>An <strong>unexpected error</strong> occured. Please Try Again later.</div>'; 

} 

?> 
+0

你的代码有问题吗?它不起作用吗?如果是这样,你会得到什么错误? – andrewsi

+0

页面提供了一条成功消息,表明邮件已发送,但电子邮件永远不会到达收件箱。没有错误信息。 –

+0

如果你拿出if/else语句,并在那里硬连线你的细节,那么怎么办?它在那种情况下工作吗? – andrewsi

回答

1

此解决方案来自@andrewsi工作。感谢您发现我的错误!

if($_POST['template-contactform-employee'] = 'Sandy')是错误的 - 您正在使用=进行平等检查,而不是==。尝试if($_POST['template-contactform-employee'] == 'Sandy'),看看是否有不同(你需要修改每个if行)。

相关问题