@mail not sending mail in php

后端 未结 5 1389
你的背包
你的背包 2020-12-17 08:00

This is the first time I am using the mail function. I tried to send a mail using this and the code tells me it\'s \"successfully sent\", but I didn\'t receive any mail. I\'

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 08:59

    Disclosure: I'm one of the developers behind AlphaMail

    Since you have no error to go on, it's not that easy to say what the issue is here. I would therefore recommend that to manually try and connect to the SMTP-server from your server and send the email manually. This way you'll have the error in hand instead of second-guessing.

    If you don't want to do this, and just want it to "work" I would recommend that you use a Transactional Email Service such as:

    • AlphaMail
    • MailGun
    • PostageApp

    Why?

    • You don't have to think that much about email delivery.
    • Statistics. Let's you track Total Sent/Clicks/Opens/Bounces.
    • Often web service-based instead of SMTP. I.e. easier to handle.
    • Cleaner code (at least if you use AlphaMail that separates data from presentation).
    • Scalable and future proof.

    If you choose to go with AlphaMail you could use the AlphaMail PHP-client.

    Example:

    include_once("comfirm.alphamail.client/emailservice.class.php");
    
    $email_service = AlphaMailEmailService::create()
        ->setServiceUrl("http://api.amail.io/v1")
        ->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
    
    $person = new stdClass();
    $person->userId = "1234";
    $person->firstName = "John";
    $person->lastName = "Doe";
    $person->dateOfBirth = 1975;
    
    $response = $email_service->queue(EmailMessagePayload::create()
        ->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
        ->setSender(new EmailContact("Sender Company Name", "from@example.com"))
        ->setReceiver(new EmailContact("Joe Doe", "to@example.org"))
        ->setBodyObject($person) // Any serializable object
    );
    

    Another advantage with AlphaMail is that you can edit your templates directly in the AlphaMail Dashboard, and you can format your emails using the Comlang template language.

    
        
            Name: <# payload.firstName " " payload.lastName #>
    Date of Birth: <# payload.dateOfBirth #>
    <# if (payload.userId != null) { #> Sign Up Free! <# } else { #> Sign In <# } #>

提交回复
热议问题