PHP mail error domain missing or malformed












-1















I'm trying to send a mail to a customers email thats set in my database.



$subject = 'Testing PHP Mail';
$txt = 'This mail is sent using the PHP mail function';
$headers = "FROM: test@gmail.com";
$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_assoc();
echo $row['email'];
$to_email = (string)$row;

//while ($row = $result->fetch_assoc()) {
// echo $row['email'];
// $to_email = (string)'$row <@>';
if (mail($to_email, $subject, $txt, $headers)) {
echo "send";
} else {
echo "failed";
}


this is my code that's need to send the email to the email out of the database.



but when i try to send it i get the error: : domain missing or
malformed










share|improve this question


















  • 1





    fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

    – Dirk Scholten
    Nov 16 '18 at 9:00













  • (string)$row returns word Array.

    – u_mulder
    Nov 16 '18 at 9:01











  • What do i need to change to dont get the whole array?

    – user10384599
    Nov 16 '18 at 9:18











  • Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

    – Álvaro González
    Nov 16 '18 at 9:23
















-1















I'm trying to send a mail to a customers email thats set in my database.



$subject = 'Testing PHP Mail';
$txt = 'This mail is sent using the PHP mail function';
$headers = "FROM: test@gmail.com";
$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_assoc();
echo $row['email'];
$to_email = (string)$row;

//while ($row = $result->fetch_assoc()) {
// echo $row['email'];
// $to_email = (string)'$row <@>';
if (mail($to_email, $subject, $txt, $headers)) {
echo "send";
} else {
echo "failed";
}


this is my code that's need to send the email to the email out of the database.



but when i try to send it i get the error: : domain missing or
malformed










share|improve this question


















  • 1





    fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

    – Dirk Scholten
    Nov 16 '18 at 9:00













  • (string)$row returns word Array.

    – u_mulder
    Nov 16 '18 at 9:01











  • What do i need to change to dont get the whole array?

    – user10384599
    Nov 16 '18 at 9:18











  • Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

    – Álvaro González
    Nov 16 '18 at 9:23














-1












-1








-1








I'm trying to send a mail to a customers email thats set in my database.



$subject = 'Testing PHP Mail';
$txt = 'This mail is sent using the PHP mail function';
$headers = "FROM: test@gmail.com";
$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_assoc();
echo $row['email'];
$to_email = (string)$row;

//while ($row = $result->fetch_assoc()) {
// echo $row['email'];
// $to_email = (string)'$row <@>';
if (mail($to_email, $subject, $txt, $headers)) {
echo "send";
} else {
echo "failed";
}


this is my code that's need to send the email to the email out of the database.



but when i try to send it i get the error: : domain missing or
malformed










share|improve this question














I'm trying to send a mail to a customers email thats set in my database.



$subject = 'Testing PHP Mail';
$txt = 'This mail is sent using the PHP mail function';
$headers = "FROM: test@gmail.com";
$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_assoc();
echo $row['email'];
$to_email = (string)$row;

//while ($row = $result->fetch_assoc()) {
// echo $row['email'];
// $to_email = (string)'$row <@>';
if (mail($to_email, $subject, $txt, $headers)) {
echo "send";
} else {
echo "failed";
}


this is my code that's need to send the email to the email out of the database.



but when i try to send it i get the error: : domain missing or
malformed







php mysql email phpmailer heidisql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 8:58







user10384599















  • 1





    fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

    – Dirk Scholten
    Nov 16 '18 at 9:00













  • (string)$row returns word Array.

    – u_mulder
    Nov 16 '18 at 9:01











  • What do i need to change to dont get the whole array?

    – user10384599
    Nov 16 '18 at 9:18











  • Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

    – Álvaro González
    Nov 16 '18 at 9:23














  • 1





    fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

    – Dirk Scholten
    Nov 16 '18 at 9:00













  • (string)$row returns word Array.

    – u_mulder
    Nov 16 '18 at 9:01











  • What do i need to change to dont get the whole array?

    – user10384599
    Nov 16 '18 at 9:18











  • Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

    – Álvaro González
    Nov 16 '18 at 9:23








1




1





fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

– Dirk Scholten
Nov 16 '18 at 9:00







fetch_assoc returns you an array. You are now putting that whole array (as a string) into the to address. My guess is you want something like $row['email'].

– Dirk Scholten
Nov 16 '18 at 9:00















(string)$row returns word Array.

– u_mulder
Nov 16 '18 at 9:01





(string)$row returns word Array.

– u_mulder
Nov 16 '18 at 9:01













What do i need to change to dont get the whole array?

– user10384599
Nov 16 '18 at 9:18





What do i need to change to dont get the whole array?

– user10384599
Nov 16 '18 at 9:18













Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

– Álvaro González
Nov 16 '18 at 9:23





Question tags say you are using PHPMailer but your code doesn't even attempt to use that library. Can you please clarify that?

– Álvaro González
Nov 16 '18 at 9:23












1 Answer
1






active

oldest

votes


















1














You only want the address, and it's the only field you're fetching, so I'd go with:



$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_row();
$to_email = $row[0];


No need to use an assoc array for this.



You've not mentioned it, but the messages you send will probably be rejected. You're sending via mail(), which means you are not sending through gmail's servers, but you're using a gmail from address. This is forgery and will mean your messages will be bounced or spam filtered. You can't solve this using mail() (other than by not using gmail for your from address); you would need to send using SMTP via gmail using PHPMailer (that you tagged this question with).






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334445%2fphp-mail-error-domain-missing-or-malformedeol%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You only want the address, and it's the only field you're fetching, so I'd go with:



    $query = ("SELECT email FROM ps_customer where id_customer = 2");
    $result = $dbc->query($query);
    $row = $result->fetch_row();
    $to_email = $row[0];


    No need to use an assoc array for this.



    You've not mentioned it, but the messages you send will probably be rejected. You're sending via mail(), which means you are not sending through gmail's servers, but you're using a gmail from address. This is forgery and will mean your messages will be bounced or spam filtered. You can't solve this using mail() (other than by not using gmail for your from address); you would need to send using SMTP via gmail using PHPMailer (that you tagged this question with).






    share|improve this answer




























      1














      You only want the address, and it's the only field you're fetching, so I'd go with:



      $query = ("SELECT email FROM ps_customer where id_customer = 2");
      $result = $dbc->query($query);
      $row = $result->fetch_row();
      $to_email = $row[0];


      No need to use an assoc array for this.



      You've not mentioned it, but the messages you send will probably be rejected. You're sending via mail(), which means you are not sending through gmail's servers, but you're using a gmail from address. This is forgery and will mean your messages will be bounced or spam filtered. You can't solve this using mail() (other than by not using gmail for your from address); you would need to send using SMTP via gmail using PHPMailer (that you tagged this question with).






      share|improve this answer


























        1












        1








        1







        You only want the address, and it's the only field you're fetching, so I'd go with:



        $query = ("SELECT email FROM ps_customer where id_customer = 2");
        $result = $dbc->query($query);
        $row = $result->fetch_row();
        $to_email = $row[0];


        No need to use an assoc array for this.



        You've not mentioned it, but the messages you send will probably be rejected. You're sending via mail(), which means you are not sending through gmail's servers, but you're using a gmail from address. This is forgery and will mean your messages will be bounced or spam filtered. You can't solve this using mail() (other than by not using gmail for your from address); you would need to send using SMTP via gmail using PHPMailer (that you tagged this question with).






        share|improve this answer













        You only want the address, and it's the only field you're fetching, so I'd go with:



        $query = ("SELECT email FROM ps_customer where id_customer = 2");
        $result = $dbc->query($query);
        $row = $result->fetch_row();
        $to_email = $row[0];


        No need to use an assoc array for this.



        You've not mentioned it, but the messages you send will probably be rejected. You're sending via mail(), which means you are not sending through gmail's servers, but you're using a gmail from address. This is forgery and will mean your messages will be bounced or spam filtered. You can't solve this using mail() (other than by not using gmail for your from address); you would need to send using SMTP via gmail using PHPMailer (that you tagged this question with).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 9:19









        SynchroSynchro

        19k85371




        19k85371
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334445%2fphp-mail-error-domain-missing-or-malformedeol%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine