【问题标题】:Mail Function is not workign in php邮件功能在php中不起作用
【发布时间】:2015-04-14 17:36:52
【问题描述】:

我必须使用图片发送电子邮件。我希望图像应该显示在电子邮件中,但没有显示图像,显示的是图像链接而不是图像。

这是我的代码,但它不起作用...

请帮帮我。

================================================ =============

我的 PHP 文件代码:

<?php

// Define some constants
define( "RECIPIENT_NAME", "Web Developer" );
define( "RECIPIENT_EMAIL", "testing@testing.com" );
define( "EMAIL_SUBJECT", "Visitor Message" );

// Read the form values
$success = false;
$success_one = false;
//$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
//$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
$subject = "Coming Soon";
$message = <<<EOF
    \n<img src="http://gettyanimations.com/conci_landing_page/images/logo.png"  />
    \nThanks you for your interest in "Conci".
    \nWe will contact you soon with more details about our services.
    \nSincerely, \n The Conci Team</td>
    \n<img src="http://gettyanimations.com/conci_landing_page/images/logo.png"  />
EOF;

// If all values exist, send the email
if ( $senderEmail ) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers = 'From: <' . $senderEmail . '>' . "\r\n";
  $headers_one = "<table><tr><td><img src='http://gettyanimations.com/conci_landing_page/images/logo.png'/></td></tr></table>";
  $footer_one = "<img src='http://gettyanimations.com/conci_landing_page/images/logo.png'/>";
  $success = mail( $recipient, EMAIL_SUBJECT, $headers );
  $success_one = mail( $senderEmail, $subject, $message );
}

// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) ) {
  echo $success ? "success" : "error";
} else {
?>
<html>
  <head>
    <title>Thanks!</title>
  </head>
  <body>
  <?php if ( $success && $success_one ) echo "<p>“Thank you for your interest in Conci. We will contact you soon with more details about our services. Sincerely, The Conci Team”</p>" ?>
  <?php if ( !$success && $success_one ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
  <p>Click your browser's Back button to return to the page.</p>
  </body>
</html>
<?php
}
?>

我的 HTML 文件代码:

<!doctype html>
<html lang="en">
<head>
<title>Conci</title>
<link rel="styleSheet" type="text/css" href="css/style.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">

var messageDelay = 2000;  // How long to display status messages (in milliseconds)

// Init the form once the document is ready
$( init );


// Initialize the form

function init() {

  // Hide the form initially.
  // Make submitForm() the form's submit handler.
  // Position the form so it sits in the centre of the browser window.
  $('#contactForm').submit( submitForm ).addClass( 'positioned' );

}


// Submit the form via Ajax

function submitForm() {
  var contactForm = $(this);

  // Are all the fields filled in?

  if ( !$('#senderEmail').val() ) {

    // No; display a warning message and return to the form
    $('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
    contactForm.fadeOut().delay(messageDelay).fadeIn();

  } else {

    // Yes; submit the form to the PHP script via Ajax

    $('#sendingMessage').fadeIn();
    contactForm.fadeOut();

    $.ajax( {
      url: contactForm.attr( 'action' ) + "?ajax=true",
      type: contactForm.attr( 'method' ),
      data: contactForm.serialize(),
      success: submitFinished
    } );
  }

  // Prevent the default form submission occurring
  return false;
}


// Handle the Ajax response

function submitFinished( response ) {
  response = $.trim( response );
  $('#sendingMessage').fadeOut();

  if ( response == "success" ) {

    // Form submitted successfully:
    // 1. Display the success message
    // 2. Clear the form fields
    // 3. Fade the content back in

    $('#successMessage').fadeIn().delay(messageDelay).fadeOut();
    $('#senderEmail').val( "" );

    $('#content').delay(messageDelay+500).fadeTo( 'slow', 1 );

  } else {

    // Form submission failed: Display the failure message,
    // then redisplay the form
    $('#failureMessage').fadeIn().delay(messageDelay).fadeOut();
    $('#contactForm').delay(messageDelay+500).fadeIn();
  }
}

</script>
</head>
<body>
    <div class="wrapper">
        <header class="header"><img src="images/logo.png"/></header>
        <section class="search">
            <h1>Welcome to Conci Bermuda!</h1>
            <h2>Something BIG is coming....</h2>
            <p>Register below to receive an invitation to the Conci experience.</p>
            <form id="contactForm" action="processForm.php" method="post">
                 <input type="email" name="senderEmail" id="senderEmail" placeholder="Your Email..." required="required" maxlength="50" />
                 <input type="submit" id="sendMessage" class="sendMessage" name="sendMessage" value="Send Email" />
            </form>

<div id="sendingMessage" class="statusMessage"><p>Sending your message. Please wait...</p></div>
<div id="successMessage" class="statusMessage"><p>Thanks for sending your message! We'll get back to you shortly.</p></div>
<div id="failureMessage" class="statusMessage"><p>There was a problem sending your message. Please try again.</p></div>
<div id="incompleteMessage" class="statusMessage"><p>Please complete all the fields in the form before sending.</p></div>           
        </section>
        <footer class="footer">
            <ul>
                <li><a href="#"><img src="images/fb-icon.png"/></a></li>
                <li><a href="#"><img src="images/twitter-icon.png"/></a></li>
                <li><a href="#"><img src="images/pinterest-icon.png"/></a></li>
            </ul>
            <div class="clear"></div>
            <p>Copyright 2015 Conci Bermuda©.  All rights reserved.</p>
        </footer>
    </div>
</body>
</html>

【问题讨论】:

  • 你必须附上那张你不能在消息中发送的图片
  • 为什么要在消息中发送 img?如果您想展示它们,请将其作为附件发送。
  • 我说的是这段代码不起作用.. $message = " /> \n感谢您对“Conci”的关注。 \n我们将尽快与您联系,提供有关我们服务的更多详细信息。 \n此致,\n Conci 团队 \ngettyanimations.com/conci_landing_page/images/logo.png" /> EOF;
  • 不是附件,应该在邮件正文中可见。
  • 检查此链接中标记的答案:- stackoverflow.com/questions/5868664/…

标签: php email


【解决方案1】:

试试这个,它应该适合你。

邮件($to, $subject, $message, $headers);

将标头作为字符串传递给mail() 的第四个参数。

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 2011-04-07
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    相关资源
    最近更新 更多