繁体   English   中英

通过PHP脚本发送电子邮件

[英]Sending email via PHP Script

我使用的是wamp服务器,并且在将表单值发送到电子邮件时使用过该php脚本。 我找不到代码所完成的工作,或者可能是我的Wamp Server吓到了,因为它不再发送并且收到错误消息:发送消息时出现问题。

码:

// Create the form
$contactForm = new JFormer('contactForm', array(
    'submitButtonText' => 'Send Message',
));

// Add components to the form
$contactForm->addJFormComponentArray(array(
    new JFormComponentSingleLineText('artistname', 'Artist Name:', array(
         'validationOptions' => array('required'),
        'tip' => '<p>Enter your artist name.</p>'
    )),
    new JFormComponentSingleLineText('trackname', 'Track Name:', array(
        'tip' => '<p>Enter your track name.</p>',
         'validationOptions' => array('required'),
    )),
    new JFormComponentSingleLineText('email', 'E-mail Address:', array(
        'tip' => '<p>Enter your email address.</p>',
         'validationOptions' => array('required'),
    )),
    new JFormComponentSingleLineText('stream', 'Link to Stream:</br>(if applicable)', array(
        'tip' => '<p>Enter your link to stream.</p>'
    )),
    new JFormComponentSingleLineText('download', 'Download Link:', array(
        'tip' => '<p>Enter your download link.</p>',
         'validationOptions' => array('required'),
    )), 

    new JFormComponentMultipleChoice('multipleChoiceType', 'Full Track or Clip:',
    array(
        array('label' => 'Full Track', 'value' => 'fulltrack'),
        array('label' => 'Clip', 'value' => 'clip'),
    ),
    array(
        'multipleChoiceType' => 'radio',
    )),
    new JFormComponentSingleLineText('downloadorpurchase', 'Free Download or 
    Purchase Link</br>(To be included in video description)', array(
        'tip' => '<p>Enter your link.</p>',
    )),
    new JFormComponentSingleLineText('releasedate', 'Release Date:</br>(if applicable)', array(
        'tip' => '<p>Enter the release date.</p>',
    )),
    new JFormComponentTextArea('artistandlabel', 'Artist / Label Links:</br>(To be included in description.)', array(
        'validationOptions' => array('required'),
        'tip' => '<p>Enter your description.</p>',
    )),
    new JFormComponentMultipleChoice('iagree', 'I confirm that I own full 
    copyright rights and grant the THU Records to post my music in their videos. I 
    understand that content may be monetized with adverts.',
    array(
        array('label' => 'I Accept', 'value' => 'accepted'),
        array('label' => 'I Do Not Accept', 'value' => 'dontaccepted'),
    ),
    array(
        'iagree' => 'radio',
         'validationOptions' => array('required'),
    )),
));



// Set the function for a successful form submission
function onSubmit($formValues) {

    // Concatenate the name
    if(!empty($formValues->name->middleInitial)) {
        $name = $formValues->name->firstName . ' ' . $formValues->name->middleInitial . ' ' . $formValues->name->lastName;
    }
    else {
        $name = $formValues->name->firstName . ' ' . $formValues->name->lastName;
    }
    // Prepare the variables for sending the mail
    $to = 'lill_z4ck3@hotmail.com';
    $fromAddress = $formValues->email;
    $trackName = $formValues->trackname;
    $streamLink = $formValues->stream;
    $download = $formValues->download;
    $trackorclip = $formValues->multipleChoiceType;
    $downloadOrPurchase = $formValues->downloadorpurchase;
    $releaseDate = $formValues->releasedate;
    $artistAndLabel = $formValues->artistandlabel;
    $agreement = $formValues->iagree;
    $artistName = $formValues->artistname;
    $subject = "Submit from ".$formValues->artistname;
    $message = "Artist Name : ".$artistName."\nTrack Name : ".$trackName."\n
     Email : ".$fromAddress."\n Stream Link : ".$streamLink."\nDownload link 
     : ".$download."\nTrack or Clip : ".$trackorclip."\nDownload or Purchase 
     : ".$downloadOrPurchase."\n Release Date : ".$releaseDate."\n Artist
      and Label Info : ".$artistAndLabel."\n Agreement : ".$agreement;

    // Use the PHP mail function
    $mail = mail($to, $subject, $message);

    // Send the message
    if($mail) {
        $response['successPageHtml'] = '
            <h1>Thanks for Contacting Us</h1>
            <p>Your message has been successfully sent.</p>
        ';
    }
    else {
        $response['failureNoticeHtml'] = '
            There was a problem sending your message.
        ';
    }

    return $response;
}

// Process any request to the form
$contactForm->processRequest();

你们当中有人知道什么地方可能出问题吗? :(

默认情况下, mail()函数通常不适用于WAMP之类的东西。 您将需要将SMTP服务器的详细信息添加到php.ini文件,然后配置其他一些设置。

这是一个很好的教程: http : //roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM