我能夠發送郵件,但沒有附件使用cron作業我可以發送郵件,但沒有使用cronjob附件...請我現在需要幫助。我在過去的兩天裏感到很震驚。phpmailer與附件不工作在cron作業
代碼:
<?php
dirname(__FILE__);
$data;
$data1;
$d1="localhost";
$d2="username";
$d3="password";
mysql_connect($d1,$d2,$d3);
$d4="database name";
mysql_select_db($d4) or die("cannot connect db");
$sql = "select * from members";
$res = mysql_query($sql) or die("cannot select db");
$count = mysql_num_fields($res);
// fetch table header from database
$header = "";
for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($res, $i);
}
// fetch data each row, store on tabular row data
while($row = mysql_fetch_row($res)){
$line = "";
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{
$value = str_replace("", "", $value);
$value = "" . $value . "" ;
}
$line .= $value;
}
$data1 .= trim($line)."\n";
$data = str_replace("\r", "", $data1);
}
$name=date("d-m-y")."-list.xls";
$ran=rand(1,1000);
$d5="exportfile";
$ourFileName =$d5;
$d6=".xls";
$et=$d6;
if(file_exists($ourFileName.$et))
file_put_contents($ourFileName.$ran.$et, $header."\n".$data);
$file=$ourFileName.$ran.$et;
require("class.phpmailer.php");
require("class.smtp.php");
require("/home/freetech/public_html/akw/PHPMailer-master/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true;
$us="username";
$pswd="password";
$hst="server link";
$frm="[email protected]"; // Enable SMTP authentication
$mail->Username = $us; // SMTP username
$mail->Password = $pswd;
$mail->SMTPSecure = 'ssl';
$mail->Host = $hst; // SMTP server
$mail->Port =465;
$mail->From = $frm;
$mail->AddAddress("email address");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail.";
$mail->AddAttachment("/home/freetech/public_html/akw/".$file); // attachment
$mail->WordWrap = 50;
$mail->Send();
?>
附件是否位於正確位置?它是否具有讀取權限? 這可能是有用的:http://stackoverflow.com/questions/15064619/php-send-email-with-attachment –
是的,我給了每一個許可和附件也在適當的位置,但不響鐘!! – user3304531
歡迎來到本網站!這裏有大量的死代碼和無意義的變量名,所以很難分析你的問題。例如,前三行完全沒有做任何事情。我建議你去讀一些基本的教程,並給你的變量有意義的名字,然後回來。 –