Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on PHP emails are sent when $message is a string, but not when its an array

Parent

PHP emails are sent when $message is a string, but not when its an array

+3
−1

I host my website on a CentOS-Bash, PHP and MySQL environment; my local email client is engined by Roundcube. I don't know almost anything about PHP nuances.

While my web domain registration is done by one company, my DNS records hosting, websites hosting and website emails hosting are all done by a second company.


I can send emails to myself (to my local email client) via running in terminal php example_1.php with:

<?php
    $to = "example@example.com";
    $subject = "Email Test";
    $message = "PHP's mail function test";

    mail($to, $subject, $message);
?>

I can't send emails to myself (to my local email client) via running in terminal php example_2.php with:

<?php
    $to = "example@example.com";
    $subject = "New email message";
    $message = array (
            $name = $_POST["name"] . "Name:" . "\r\n",
            $email = $_POST["email"] . "Email:" . "\r\n",
            $phone = $_POST["phone"] . "Phone:" . "\r\n",
            $topic = $_POST["topic"] . "Topic:" . "\r\n",
            $date = $_POST["date"] . "Date:" . "\r\n",
            $time = $_POST["time"] . "Time:" . "\r\n",
            $notes = $_POST["notes"] . "Notes:" . "\r\n"
    );

    mail($to, $subject, $message);
?>

What might cause messages by the second example pattern not to reach my email box?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+3
−0

As explained by manassehkatz, the message (aka the body) is a text in PHP (and many other programming languages).

If your e-mails have a certain structure, you should create a function that takes that structure (i.e. your array) and generate a string from it. This is a good idea also from an architectural point of view because separating body construction from the actual e-mail sending functionality is preferred.

Also, you should take care of the message format (plain text vs. HTML) as it might involve some changes (e.g. using <p>s or <br>s instead of newlines).

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (2 comments)
General comments
deleted user wrote over 3 years ago · edited over 3 years ago

Thank you Alexei, about your last suggestion about plain text vs. HTML ; did you mean to an header such as header("Content-Type: text/html; charset=UTF-8");?

Alexei‭ wrote over 3 years ago

@JohnDoea Yes, I think that is the way to define the message content type.