phpMailer不会通过我的GoDaddy电子邮件发送嵌入图像?

时间:2013-07-11 09:37:58

标签: php phpmailer contact-form

我让脚本工作了一段时间,但忘记备份了,忘记了我是如何使用SMTP从我的GoDaddy电子邮件中发送嵌入电子邮件的。我收到的唯一电子邮件来自“f5e66463@p3nlhg1093.shr.prod.phx3.secureserver.net”。

这就是我现在的观点:

inv.php

<?php
require_once('phpMailer/class.phpmailer.php');
require_once('phpMailer/language/phpmailer.lang-en.php');

    date_default_timezone_set('America/Detroit');

    // PHP mail version (default)

    $mail = new PHPMailer(true);
    $mail->IsSMTP(); // Using SMTP.
    $mail->SMTPDebug = 1; // Enables SMTP debug information - SHOULD NOT be active on production servers!
    $mail->Host = "relay-hosting.secureserver.net"; // SMTP server host.
    $mail->Username = 'username@godaddydomain.com';
    $mail->Password = 'godaddypassword';

    $mail->IsHTML(true);
    $mail->Body="
    Your Name: $from_name
    Your E-Mail: $from
    Friends Name: $to_name
    Friends E-Mail: $to";
    $from_name = $_REQUEST['your-name'];
    $from = $_REQUEST['your-email'];
    $to_name = $_REQUEST['friends-name'];
    $to = $_REQUEST['friends-email'];
    $subject = 'Mail Test at '.strftime('%T', time());
    $message = '<img src="cid:video2">';

    $mail->AddAddress('testmail@test.te');
    $mail->AddEmbeddedImage('video.jpg','video2','video.jpg');


    $result = mail($to, $from, $subject, $message, $headers);
    if(!$mail->Send()) {
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message sent!';
    }
?>

invite.html

<form action="inv.php" method="post" id="ContactForm">
                    <fieldset>
                        <ol>
                            <li>
                                <label for=name>Your Name</label>
                                <input id="from_name" name="from_name" type="text" placeholder="from_name" required autofocus>
                            </li>


                            <li>
                                <label for=email>Your Email</label>
                                <input id="your-email" name="your-email" type="your-email" placeholder="example@domain.com" required>
                            </li>


                            <li>
                                <label for=name>Friends Name</label>
                                <input id="to_name" name="to_name" type="text" placeholder="to_name" required autofocus>
                            </li>


                            <li>
                                <label for=email>Friends Email</label>
                                <input id="friends-email" name="friends-email" type="friends-email" placeholder="example@domain.com" required>
                            </li>

                        </ol>
                    </fieldset>

              <fieldset>
                        <button type=submit>submit</button>
                    </fieldset>

                </form>

1 个答案:

答案 0 :(得分:0)

问题出在这里,

AddEmbeddedImage()函数需要两个参数

       1. path of the image
       2. CID number ie, Content-ID of the attachment, generally random number.

所以,你的程序是这样的

 $cid1=date("Ymdhis").rand(1000,9999);
 $cid2=date("Ymdhis").rand(1000,9999);

 $mailObj->AddEmbeddedImage('pic1.jpg',$cid1);
 $mailObj->AddEmbeddedImage('pic2.jpg',$cid2);
 ............
 ...........
相关问题