2016-03-07 43 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); 
}