2016-03-07 45 views
0

我试图根据可用的变量进行电子邮件更改。PHP:尝试发送带有变量和IF语句的电子邮件表格

总共有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?

我目前得到这个错误提前

`Parse error: syntax error, unexpected T_IF in /var/www/ps_t/send_form_email.php on line 21 Call Stack: 0.0004 656768 1. {main}() /var/www/ps_t/punch.php:0` with the code used above.

感谢。

回答

2

试试这个代码

$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); 
1

试试这个:

$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); 
+0

感谢您的。这真的很简单...... – Moms

0

试试这个:

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); 
}