0

我需要添加一个条件。如果$contact_subject大于数字 50000,它应该转到一个电子邮件地址,如果它更小,它应该转到另一个电子邮件地址。

if( $contact_name == true )
{
    $sender = $contact_email;
    $receiver = "email@email.com";
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $email_body = "Name: $contact_name \nEmail: $sender \nAccount Number: $contact_subject \nMessage: $contact_message \nIP: $client_ip \nEmail Sent from website http://www.website.com";      
    $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

    if( mail( $receiver, "Email From Website - $subject", $email_body, $extra ) ) 
    {
        echo "success=yes";
    }
    else
    {
        echo "success=no";
    }
}
4

2 回答 2

1

使用三元语句检查是否$contact_subject大于 50000 并$receiver根据条件设置电子邮件地址。

$receiver = ($contact_subject > 50000) ? 'abc@example.com' : 'xyz@example.com';

同样可以使用if-else块来完成。

if ($contact_subject > 50000) {
    $receiver = 'abc@example.com';
}
else {
    $receiver = 'xyz@example.com';
}
于 2013-08-26T17:11:52.290 回答
0

也许更好的方法是将大小放入可变数字中。

-> config.php
    $size_mail = '5000';


-> mail.php
include "config.php";
if( $contact_name == true )
    {

    if($contact_subject > $size_mail)
    {$receiver = 'mailone@nobody.com';}else{$receiver == 'mailtwo@nobody.com';}

        $sender = $contact_email;
        $client_ip = $_SERVER['REMOTE_ADDR'];
        $email_body = "Name: $contact_name \nEmail: $sender \nAccount Number: $contact_subject \nMessage: $contact_message \nIP: $client_ip \nEmail Sent from website http://www.website.com";      
        $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

        if( mail( $receiver, "Email From Website - $subject", $email_body, $extra ) ) 
        {
            echo "success=yes";
        }
        else
        {
            echo "success=no";
        }
    }
于 2013-08-26T17:25:34.237 回答