English 中文(简体)
凭据不能见
原标题:Attached file cannot be Viewed
  • 时间:2012-04-25 07:29:17
  •  标签:
  • php

我通过php邮件寄送电子邮件。 在这方面,我收到了简便(文本)邮件。 当我附上档案时,我收到电子邮件的附文,但当我试图看到时,档案总是空白,即便是它的一种PDF格式! 请帮助我。 我的寄信页的代码如下:

include_once("db_connect.php");
session_start();
error_reporting(16);
require_once( class.phpmailer.php );//Getting values from Session
$tot = $_SESSION[ $tot ];
$from = $_SESSION[ from ];
$message = $_SESSION[ message ];
$subject = $_SESSION[ subject ];
$full_nm = $_SESSION[ firstnm ]." ".$_SESSION[ lastnm ];
$temp_passwd = $_SESSION[ e_pwd ];
$email_use = $_SESSION[ email ];

function send_mail($to, $message, $subject, $from, $temp_passwd, $full_nm, $email_use)
{
    $message_org      = nl2br($message);
    $mail             = new PHPMailer();
    $body             = $message_org;
    $mail->IsSMTP(); 
    $mail->SMTPAuth   = true;
    $mail->SMTPSecure = "ssl";
    $mail->AddAttachment("Uploads/file.pdf");
    $mail->ContentType = "mutlipart/alternative";
    $mail->Host       = "smtp.mail.yahoo.com";
    $mail->Port       = 465;
    $mail->Username   = $from;
    $mail->Password   = $temp_passwd;
    $mail->SetFrom($from, $full_nm);
    $mail->Subject    = $subject;
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, $address);

    if(!$mail->Send())
    {
        $err_send = "Mailer Error: " . $mail->ErrorInfo;
    }
        else
    {
        $err_send = "";
    }
}
foreach($tot as $to_trim)
{
    $to = trim($to_trim);
    send_mail($to, $message, $subject, $from, $temp_passwd, $full_nm, $email_use);
    echo $err_send;
}

The function AddAttachment in class.phpmailer.php is as follows:

public function AddAttachment($path, $name =   , $encoding =  base64 , $type =  application/octet-stream ) {
try {
  if ( !@is_file($path) ) {
    throw new phpmailerException($this->Lang( file_access ) . $path, self::STOP_CONTINUE);
  }
  $filename = basename($path);
  if ( $name ==    ) {
    $name = $filename;
  }

  $this->attachment[] = array(
    0 => $path,
    1 => $filename,
    2 => $name,
    3 => $encoding,
    4 => $type,
    5 => false,  // isStringAttachment
    6 =>  attachment ,
    7 => 0
  );

} catch (phpmailerException $e) {
  $this->SetError($e->getMessage());
  if ($this->exceptions) {
    throw $e;
  }
  echo $e->getMessage()."
";
  if ( $e->getCode() == self::STOP_CRITICAL ) {
    return false;
  }
}
return true;
}
问题回答

When you do $mail->AddAttachment("Uploads/file.pdf"); If you put the add attachment in an "if file exists add attachment" clause, does the file not get attched? Im thinking "Uploads/file.pdf" isnt sufficient pathing.

在该行之前进行一项PHP测试,以确定档案是否确实存在:

// Change this
$mail->AddAttachment("Uploads/file.pdf");

// To this...
$attachment = "Uploads/file.pdf";
$mail->AddAttachment($attachment);

// And then to this
$attachment = "Uploads/file.pdf";
if(!file_exists($attachment) && !file_exists(getcwd(). / .$attachment)
{
    die(sprintf("attachment: %s does not exist", $attachment));
}
$mail->AddAttachment($attachment);

我是向大家表明我的想法的中间步骤。

我先测试了<代码>if的说明,但这一想法是为了确保<代码>attachment/code>变量是有效的绝对(第一部分)或相对(第二部分)途径。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签