PHP:尝试发送包含变量和 IF 语句的电子邮件表单


PHP: Trying to send an email form with variables and an IF statement

我正在尝试根据可用的变量更改电子邮件。

总共有 6 个操作

ID,但是与其他操作不同,有 20 个(代码中如下所示的那个)需要机器代码。

$email = 
if ($OperationID == 20)
    {
        'Machine: '.$machCode."'r'n".
    }
"JobID: ".$jobid."'r'n" . 
"PartID: ".$part_id."'r'n" .
"'nNote: ".$message."'r'n";
@mail($email_to, $email_subject, $email); 

如果没有"if声明",可以发送如下所示的电子邮件

Machine:
JobID: 123456789
PartID: 123456789
Note: Test

我不想要这个,因为"机器"旁边有一个空白处。我希望移除机器生产线,除非显然OperationID是 20。因此,电子邮件如下所示:

JobID: 123456789
PartID: 123456789
Note: Test

如何使机器生产线仅在操作等于 20 时激活?

我目前收到此错误

'解析错误:语法错误,第 21 行/var/www/ps_t/send_form_email.php 中的意外T_IF调用堆栈:0.0004 656768 1。{主要}()/var/www/ps_t/punch.php:0' 使用上面使用的代码。

提前谢谢。

试试这段代码

$email = "";
if ($OperationID == 20)
{
     $email .= 'Machine: '.$machCode."'r'n";
}
$email .= "JobID : ".$jobid."'r'n" . 
          "PartID: ".$part_id."'r'n" .
          "'nNote: ".$message."'r'n";
@mail($email_to, $email_subject, $email); 

尝试以下操作:

$email = '';
if ($OperationID == 20)
{
        $email .= 'Machine: '.$machCode."'r'n";
}
$email .= "JobID: ".$jobid."'r'n" . 
          "PartID: ".$part_id."'r'n" .
          "'nNote: ".$message."'r'n";
@mail($email_to, $email_subject, $email); 

试试这个:

if ($OperationID == 20)
{  
    $email = "Machine: ".$machCode."'r'n".
             "JobID: ".$jobid."'r'n" . 
             "PartID: ".$part_id."'r'n" .
             "'nNote: ".$message."'r'n";
    @mail($email_to, $email_subject, $email);
}
else
{
    $email = "JobID: ".$jobid."'r'n" . 
             "PartID: ".$part_id."'r'n" .
             "'nNote: ".$message."'r'n";
    @mail($email_to, $email_subject, $email);
}