Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29745

PHP mail() function sending mail but being received blank

$
0
0

I am using PHP's mail function to send mail from my website, this had been working until recently when I changed the content of the actual message.

I have tried changing the content back but the same thing happens.

I do actually recieve the message and I can see the message content when I view the original message header but the actual email looks blank.

This is how I am sending the emails:

$to = [customer_email];
$subject = [email_subject];

$message_header= [message_header];
$message_content= [message_content];
$message_footer = [message_footer ];

$uid = md5(uniqid(time()));

$headers = "From: support@domain.com" . "\r\n";
$headers .= "Reply-To: support@domain.com" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n";
$headers .= "Bcc: sales@domain.com" . "\r\n";

$message = "--".$uid."\r\n";
$message .= "Content-type:text/html; charset=UTF-8" . "\r\n";
$message .= $message_header.$message_content.$message_footer . "\r\n\r\n";

mail($to, $subject, $message, $headers);

Like I said, the message is being sent and received and not being marked as spam but just appears blank but the content can be seen in the message header.

The full message header is here with just the details such as the domain and email addresses changed:

Delivered-To: it@example.com
Received: by 2002:a92:a047:0:0:0:0:0 with SMTP id b7csp3413998ilm;
        Tue, 12 Nov 2019 02:40:36 -0800 (PST)
X-Received: by 2002:a1c:dd06:: with SMTP id u6mr3380338wmg.109.1573555236560;
        Tue, 12 Nov 2019 02:40:36 -0800 (PST)
ARC-Seal: i=3; a=rsa-sha256; t=1573555236; cv=pass;
        d=google.com; s=arc-20160816;
        b=yW1gv+dBt0A/d/YPiLlXTyHZpPj5ImvpnZFs48/mV4D3OxnuPdXLzr32lkkzaSIhJ5
         DsXg9gjJbvsqPSsq0bdHSliVewxEcKqRYo2PGtlzBO47apCHKzAO3BjHFKL//A6MaGTE
         tzH5Eo7lwas1Ebq0lO3D9wyb//8Qp08ghABKIlDaHA5bhOWwiBal+sS3i+lHcsVzucx1
         65K1BA7uyyi+T4VNm9NQfklFBRH7fVPBGSxNItdPFhjq2M9iqBtJnquf4lbdeQoS2XxV
         3wVM7o2Rbojz/cUkiYx/GdE4EmKRV30Ws6+MHkm2lKPzA+xQmTprqu3S4qsuDWUcZ5Uo
         /Z0w==
ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:date:message-id:mime-version
         :reply-to:from:subject:to;
        bh=Ibrhyqugys65Y8gzuSGloywNGoGY735hgcq1co4q+S8=;
        b=t2j1MvmNYcAlMt5Jkc+e4fImPECZ1+HqFd+QyCHe7dg0VwXDDZmxavpE93d9/FLCwG
         b9TGvdowKYr8eTrIzj8gvLPpzIN0KnK4xeBqzc6N9jDECfIU85tbW3ecSPvdBMEWBnQS
         pdtyrvl60Ph07Vu0cS7jlIOkHYbx84Z/geTW26pdS1mkecwxtV6WYyxrDVD+ZB0GBmql
         0UnU85ubA56tKy2WfcaKEY4nZf98wSFuyombgFD5gwqUdJRWU3997mzjzzgoLX/kbAXo
         3xBtnRj/nibLxUivbx2ABkND4eKw/lJcF+tuqIW2SXXl5HeVQb/jhPF5DmzHwGvZGPV/
         dL7g==
ARC-Authentication-Results: i=3; mx.google.com;
       arc=pass (i=2 spf=pass spfexample=our_shared_server);
       spf=pass (google.com: example of sales+bncbcb3zg7v6mnbbjeyvlxakgqe2rwanzi@example.com designates 209.85.220.69 as permitted sender) smtp.mailfrom=sales+bncBCB3ZG7V6MNBBJEYVLXAKGQE2RWANZI@example.com
Return-Path: <sales+bncBCB3ZG7V6MNBBJEYVLXAKGQE2RWANZI@example.com>
Received: from mail-sor-f69.google.com (mail-sor-f69.google.com. [209.85.220.69])
        by mx.google.com with SMTPS id z22sor1615053wml.11.2019.11.12.02.40.36
        for <it@sublift.ie>
        (Google Transport Security);
        Tue, 12 Nov 2019 02:40:36 -0800 (PST)
Received-SPF: pass (google.com: example of sales+bncbcb3zg7v6mnbbjeyvlxakgqe2rwanzi@example.com designates 209.85.220.69 as permitted sender) client-ip=209.85.220.69;
Authentication-Results: mx.google.com;
       arc=pass (i=2 spf=pass spfexample=our_shared_server);
       spf=pass (google.com: example of sales+bncbcb3zg7v6mnbbjeyvlxakgqe2rwanzi@example.com designates 209.85.220.69 as permitted sender) smtp.mailfrom=sales+bncBCB3ZG7V6MNBBJEYVLXAKGQE2RWANZI@example.com
ARC-Seal: i=2; a=rsa-sha256; t=1573555236; cv=pass;
        d=google.com; s=arc-20160816;
        b=AFvKNFKKKd+cTeGeS69+AqLOH/SZX9ku5Tl1wAJju+UPieNQ+EbhNSmbTWmBNXM5sU
         J2Cv8XaS8/YyiQSPXA5S3YywPa5/cMjl7SAzrOEQ8ip6XqJesJvfnl13v0WlIzMdL/ez
         IXvZclHuKUYeWf/2FiJKac5fvfAe9lSNVhiZUMntOO9C6SZ4FaUNYCXPhCP4nDaKdlbw
         1HPO4L9K0DbpUgrULwuyxrn6/c74+aBWp3zQVKGUR8WkAQNFbK2WczieoC37oQb97++t
         LLEag0/fbqFlHBbe6RDW9nu4DV+xdygpzVia0ZtpunlOQNMzHdqMtr2cCCcTlv9yZrq7
         TQjg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:date:message-id:mime-version
         :reply-to:from:subject:to;
        bh=Ibrhyqugys65Y8gzuSGloywNGoGY735hgcq1co4q+S8=;
        b=tl6rdsQkSCuMrMzwtYjrFqLxOs4ULy4avLhUfo4X0oA4qBh0jr4scaIhqnavMVsFf9
         9+5oojLOdX+N0ERH4NiTRXjxZIDaDPaCFnpPWcLUVtvri2mj6oAZwutpqXeXDnmOSWG3
         jIza7m36fEpwzttv+dsY53Prz4dSuNRvSwMfpKqDbZNEvraAJDHGJHkEWeCviXsfPEeD
         fqJqs1KaTnoL34EXbbl6V+US0yGeZ8+aYluqjmMvuAwIHf+YUfXJGEvToHI5ePFbFMRA
         b2MHypEDhsV1IH8e+bExAN5fotOa+Z6fPWCgwIkzD6tyDuhUlBgvppowz22wtFjt+8pO
         3/Lg==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: example of our_account@our_shared_server designates 81.88.62.181 as permitted sender) smtp.mailfrom=our_account@our_shared_server
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:to:subject:from:reply-to:mime-version:message-id
         :date:x-original-sender:x-original-authentication-results:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=Ibrhyqugys65Y8gzuSGloywNGoGY735hgcq1co4q+S8=;
        b=hvY5DqV35j9YgMHtcIWa/jwiBl3ymOb73MLuD47HnYCV4sQuixJDn2dF/10Nbgf+tE
         fLZMlODwKxQdl7CWeTfE8qQ63y3ipPK3I0JrG8wE9R0NrJfgTbgbh/loqWl5azT7DtS3
         SC3ArO+c6qgWlvUAocV8uIHmj6cYdRzb4PnopqUlAu85Gl3pjZ/zvIQkUwVjZeWwX74Y
         TWBQARVdGffN64l0DCYVuncsiF8wm5Mvc+A9gJCX7BSU2BSCNfAnBIp8Eu4YtTDnfdkl
         JIRO8O5RLCCMoNQxGuzWwKD+uRY0aJ2R2p9x9JPTbY5EPqgzBLPRpaZaWdNOx0eV4Yee
         JWkA==
X-Gm-Message-State: APjAAAUMKCJmaOwi4KPGSc+OEF7i6wHpGyVCQMH04KnB1oITD1IWmx51 Tt3YJZ970VySfVgslwxfUWrOolNg
X-Google-Smtp-Source: APXvYqxBgjxy7ZmTX8y13XVszPIbuCpHbuqu/FSXEaDemu50dSm0jsNbiWyaWNQ3RWFbr6h8zbbQZQ==
X-Received: by 2002:a7b:c7c7:: with SMTP id z7mr3057676wmk.133.1573555236294;
        Tue, 12 Nov 2019 02:40:36 -0800 (PST)
X-BeenThere: sales@example.com
Received: by 2002:adf:f74c:: with SMTP id z12ls1801906wrp.10.gmail; Tue, 12 Nov 2019 02:40:35 -0800 (PST)
X-Received: by 2002:a5d:4b05:: with SMTP id v5mr4137078wrq.210.1573555235752;
        Tue, 12 Nov 2019 02:40:35 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1573555235; cv=none;
        d=google.com; s=arc-20160816;
        b=y1naNum4xW3tsMG3wPcDM1RwyX2OQ3SaChp7jlb3ZW4oGXExBL3kKLhixVT1Z9DAri
         +UnJVlnpeoh0Kx4v9sQB9ddhxCPPQlIRCHKWhtIr2zCrsItX3ODh2Rb/8JfxIW9E4FbH
         yba1H/TzGIcdMZXPQ38FVQwq1Q38FPpFs1+EfHV+Lubpkcrfuyy2gWKgi3cub9kl/laz
         9w42Y//Y8M5KUR4VHnAMcuVh5sQxad/26Tp220QtQiZgxYTqdZZifjQd1g7hT+msups7
         Q+voJdIwBuYaQ9T3KMW9lUM88wbNnKCBdZ4EShX8kKPJj52aZhKph05OhppvEOTbhs+G
         z1xQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=date:message-id:mime-version:reply-to:from:subject:to;
        bh=daDFaRYMOJpKRlRfbGKf2aIGxQj8IKYJpLd93m4btCM=;
        b=a504IJnGdbjiRO+veK8xPAMZrl8foX/NAew/pNX/OsGhYzSlgc+jy41vYemo1CXPom
         LzLzsj7ploMCdcKGMih0s88gWDJ127AUktuYYto6nZ4EzCQxebOsSNf4hkWFeQQaq5cK
         TG8PJYP+B+rXJn4GqPjGY12Uee8Fad7cfG9qShnmbvtjKgKb5MUyApi1pwNNX5IZUP2Y
         r6jR2WFteD4u9vfovY7eqxsims/RjtqgFq/cTkzssjrelg21UPb0opQvYWectewJ5cY1
         xjArgLix9Kfu+Yxc4UN+rAtosfjVN/h6NMDDX2bQJf2FK5mIZ3kfAQCayKaEdE51Lrys
         B8hQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: example of our_account@our_shared_server designates 81.88.62.181 as permitted sender) smtp.mailfrom=our_account@our_shared_server
Received: from hostingsmtp.register.it (hostingsmtp92.register.it. [81.88.62.181])
        by mx.google.com with ESMTPS id y6si2240288wmc.143.2019.11.12.02.40.35
        for <sales@example.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 12 Nov 2019 02:40:35 -0800 (PST)
Received-SPF: pass (google.com: example of our_account@our_shared_server designates 81.88.62.181 as permitted sender) client-ip=81.88.62.181;
Received: from private ([172.22.16.122]) by cmsmtp with ESMTP id UTb9iOMwlYLluUTb9iEdpb; Tue, 12 Nov 2019 11:40:35 +0100
Received: from our_account by our_shared_server with local (Exim 4.92) (envelope-from <our_account@our_shared_server>) id 1iUTb9-002mpw-8E; Tue, 12 Nov 2019 11:40:35 +0100
X-RID-REQUEST_URI: www.example.com/beta/admin/sales/invoice.php?id=IE0811190629
X-RID-HTTP_HOST: www.example.com
To: customer@gmail.com
Subject: New Invoice from example.
X-PHP-Script: www.example.com/beta/admin/sales/invoice.php for 86.45.249.162
X-PHP-Filename: /home/our_account/public_html/beta/admin/sales/invoice.php REMOTE_ADDR: 86.45.249.162
From: support@example.com
Reply-To: support@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="25a0b6981ab0acdbcaacc68fe4994b02"
Message-Id: <E1iUTb9-002mpw-8E@our_shared_server>
Date: Tue, 12 Nov 2019 11:40:35 +0100
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - our_shared_server
X-AntiAbuse: Original example - www.example.com
X-AntiAbuse: Originator/Caller UID/GID - [754 497] / [47 12]
X-AntiAbuse: Sender Address example - our_shared_server
X-Get-Message-Sender-Via: our_shared_server: authenticated_id: our_account/from_h
X-Source: 
X-Source-Args: 
X-Source-Dir: example.com:/public_html/beta/admin/sales
X-CMAE-Envelope: MS4wfL0gy4GxoHsyyUQGrMTaqxh/6qCROIdJJMpuX7KJAKp3suZnPt0rsgCiXoQPZ1cq9Y2VDDMNcE0sFQm+GgTA/9bmUdtOITTjkTzncjKCr+IeRb6W1yGf nX7zxY3z/ZDx28i7T84m7pT1xHK6s+o8lGkfAsN9hN9aJyj4O/x33VVQVW547IvJyrebTAXh2xB2NQ2sls52aOBBV6a7vb2bORQ=
X-Original-Sender: support@example.com
X-Original-Authentication-Results: mx.google.com;
       spf=pass (google.com: example of our_account@our_shared_server designates 81.88.62.181 as permitted sender) smtp.mailfrom=our_account@our_shared_server
Precedence: list
Mailing-list: list sales@example.com; contact sales+owners@example.com
List-ID: <sales.example.com>
X-Spam-Checked-In-Group: sales@example.com
X-Google-Group-Id: 751537614565
List-Post: <https://groups.google.com/a/example.com/group/sales/post>, <mailto:sales@example.com>
List-Help: <https://support.google.com/a/example.com/bin/topic.py?topic=25838>, <mailto:sales+help@example.com>
List-Archive: <https://groups.google.com/a/example.com/group/sales/>
List-Subscribe: <https://groups.google.com/a/example.com/group/sales/subscribe>, <mailto:sales+subscribe@example.com>
List-Unsubscribe: <mailto:googlegroups-manage+751537614565+unsubscribe@googlegroups.com>, <https://groups.google.com/a/example.com/group/sales/subscribe>

--25a0b6981ab0acdbcaacc68fe4994b02
Content-type: text/html; charset=UTF-8
<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head><body style='background-color: #ddd;color:#333'><div style='width:550px;margin:auto;background-color:#fff;'><div style='text-align:center;width:500px;margin:auto;background-color:#fff;padding-left:25px;padding-right:25px;'><a class='logo' href='https://example.com/'><img src='https://example.com/media/example_logo_bg.png' alt='example.com' border='0' /></a></div><div style='width:450px;margin:auto;background-color:#fff;padding-left:25px;padding-right:25px;vertical-align:top;'>Paddy Hallihan,<br /><br />Please see below a link to your invoice.<br /><br /><a href='https://www.example.com/docs/invoices/IE0811190629.pdf'>https://www.example.com/docs/invoices/IE0811190629.pdf</a><br /><br />If you have any questions or if there is anything more we can do for you please let us know.</div><script type="application/json+trustpilot">{"recipientName": "Paddy&nbsp;Hallihan","recipientEmail": "phallihan@gmail.com","referenceId": "IE0811190629","products": [{"productUrl": "https://www.example.com/product/test1/1","imageUrl": "https://www.example.com/media/product_images/test1_0.jpg","name": "A2 - Quality Test Product - Not For Sale","sku": "402",},]}</script><div style='text-align:center;width:500px;margin:auto;background-color:#fff;padding:25px;'><span style='display:inline-block;text-align:center;vertical-align:top;'><img src='https://example.com/media/icons/phone.png' width='50px' height='50px'><br>International: <a href='tel:+35319012030'>+353 1 901 2030</a><br>United Kingdom: <a href='tel:+442036422217'>+44 20 3642 2217</a><br>United States: <a href='tel:+442036422217'>+1 888 213 8714</a></span><span style='display:inline-block;text-align:center;vertical-align:top;'><img src='https://example.com/media/icons/message.png' width='50px' height='50px'><br>Sales: <a href='mailto:sales@example.com' target='_blank'>sales@example.com</a><br>Support: <a href='mailto:support@example.com' target='_blank'>support@example.com</a></span></div></div></body></html>


--25a0b6981ab0acdbcaacc68fe4994b02--

I know there are tools like phpmailer but I want to figure this out so I understand what is happening. any help or suggestions with this would be greatly appreciated.

//-----EDIT-----//

So a bit more information:

  • I've a few different areas where emails are being sent from but the header and footer are always the same just the body of the email changes, hence why I have $message .= $message_header.$message_content.$message_footer . "\r\n\r\n";

  • I am also translating the message content variable using gettext (https://www.gnu.org/software/gettext/). These are translating fine and I can see it fine in the message header of the blank email received.

  • Like I said, I have a few emails being sent from our system, the ones with the issues are all coming from my admin subdirectory, however, I also have a components subdirectory which has a mailing list sign up component which is included indirectly (included in another included file) in my main directory and this works fine.

//-----EDIT2-----//

I kind of half resolved this by removing the following lines

$message = "--".$uid."\r\n";
$message .= "Content-type:text/html; charset=UTF-8" . "\r\n";

And by changing:

$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n";

to:

$headers .= "Content-Type: text/html;charset=UTF-8" . "\r\n";

The reason I had this in the first place was because I had been adding an attachment previously.

$message .= $message_header.$message_content.$trustpilot_script.$message_footer . "\r\n\r\n";

// $message .= "--".$uid."\r\n";
// $message .= "Content-Type: application/octet-stream; name=\"".$file_name.".pdf\"\r\n";
// $message .= "Content-Transfer-Encoding: base64" . "\r\n";
// $message .= "Content-Disposition: attachment; filename=\"".$file_name.".pdf\"\r\n";
// $message .= $content."\r\n";
// $message .= "--".$uid."--";

mail($to, $subject, $message, $headers);

I just hadn't included the commented out section of code in my original question but is there a way to get this to be able to send attachments as well?


Viewing all articles
Browse latest Browse all 29745

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>